接口地址:http://route.showapi.com/341-1 |
---|
返回格式:json |
请求方式:get/post |
请求示例:http://route.showapi.com/341-1?showapi_appid=&showapi_sign= |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
page | String | 选填 | 第几页。 |
maxResult | String | 选填 | 每页最大记录数。其值为1至50。 |
名称 | 类型 | 说明 |
---|---|---|
allNum | String | 所有记录数 |
allPages | String | 所有页数。每页20条。 |
contentlist | JokeItem[] | 笑话条目内容 |
title | String | 笑话标题 |
text | String | 笑话正文 |
ct | String | 生成时间 |
type | Number | 1为文本,2为图片,3为动态图 |
id | String | 每条笑话的id |
currentPage | String | 当前第几页 |
maxResult | String | 每页最多显示几条 |
ret_code | String | 0为成功,其他失败 |
{
"showapi_res_code": 0,
"showapi_res_error": "",
"showapi_res_body": {
"allNum": 933,
"allPages": 47,
"contentlist": [{
"ct": " 2015-07-10 05:54:00.000",
"text": " 男生拉着女生沮丧着脸说,再给我一次机会,求求你!说好不提分手的!<br />\r\n 女生甩开男孩的手说:你TM现在在我心里就是个菩萨,除了拜拜我什么都不想做。",
"title": "你TM现在在我心里就是个菩萨"
}],
"currentPage": 1,
"maxResult": 20
}
}
错误码 | 说明 |
---|---|
-1 | 系统调用错误 |
-2 | 可调用次数或金额为0 |
-3 | 读取超时 |
-4 | 服务端返回数据解析错误 |
-5 | 后端服务器DNS解析错误 |
-6 | 服务不存在或未上线 |
-1000 | 系统维护 |
-1002 | showapi_appid字段必传 |
-1003 | showapi_sign字段必传 |
-1004 | 签名sign验证有误 |
-1005 | showapi_timestamp无效 |
-1006 | app无权限调用接口 |
-1007 | 没有订购套餐 |
-1008 | 服务商关闭对您的调用权限 |
-1009 | 调用频率受限 |
-1010 | 找不到您的应用 |
-1011 | 子授权app_child_id无效 |
-1012 | 子授权已过期或失效 |
-1013 | 子授权ip受限 |
public static void main(String path[]) throws Exception {
URL u = new URL("http://route.showapi.com/341-1?showapi_appid%3Dmyappid%26page%3D1%26maxResult%3D20%26showapi_sign%3Dmysecret");
InputStream in = u.openStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte buf[] = new byte[1024];
int read = 0;
while ((read = in .read(buf)) > 0) {
out.write(buf, 0, read);
}
} finally {
if ( in != null) {
in .close();
}
}
byte b[] = out.toByteArray();
System.out.println(new String(b, "utf-8"));
}
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/3/15 17:50
*/
//----------------------------------
// 易源 笑话大全——文字 调用类
//----------------------------------
class freeApi{
private $apiId = false; //聚合appid
private $apiSecret = false; //易源secret
private $apiUrl = 'http://route.showapi.com/341-1';
public function __construct($apiid,$secretkey){
$this->apiId = $apiid;
$this->apiSecret = $secretkey;
}
/**
* url拼接
* @return string
*/
private function handleParam($paramArr,$showapi_secret){
$paraStr = "";
$signStr = "";
ksort($paramArr);
foreach ($paramArr as $key => $val) {
if ($key != '' && $val != '') {
$signStr .= $key.$val;
$paraStr .= $key.'='.urlencode($val).'&';
}
}
$signStr .= $showapi_secret;//排好序的参数加上secret,进行md5
$sign = strtolower(md5($signStr));
$paraStr .= 'showapi_sign='.$sign;//将md5后的值作为参数,便于服务器的效验
return '?'.$paraStr;
}
/**
* 将JSON内容转为数据,并返回
* @param string $content [内容]
* @return array
*/
public function returnArray($content){
return json_decode($content,true);
}
/**
* 获取 笑话大全——文字 结果
* @return array
*/
public function getResult(){
$paramArr = [
'showapi_appid'=> $this->apiId,
'page'=> "1",
'maxResult'=> "20"
];
return $this->returnArray($this->freeApiCurl($this->apiUrl.$this->handleParam($paramArr,$this->apiSecret)));
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
public function freeApiCurl($url,$params=false,$ispost=0){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
return false;
}
curl_close( $ch );
return $response;
}
}
//推荐使用npm安装使用sdk: npm install --save showapi-sdk
'use strict';
var showapiSdk = require('showapi-sdk');
//设置你测试用的appId和secret,img
var appId='';
var secret='';
//开启debug
//showapiSdk.debug(true);
if(!(appId&&secret)){
console.error('请先设置appId等测试参数,详见样例代码内注释!')
return;
}
//全局默认设置
showapiSdk.setting({
url:"http://route.showapi.com/341-1",//你要调用的API对应接入点的地址,注意需要先订购了相关套餐才能调
appId:appId,//你的应用id
secret:secret,//你的密钥
timeout:5000,//http超时设置
options:{//默认请求参数,极少用到
testParam:'test'
}
})
var request=showapiSdk.request();
request.appendText('page','1');
request.appendText('maxResult','20');
request.post(function(data){
console.info(data)
})
package main
import (
"showSdk/normalRequest"
"fmt"
)
res := normalRequest.ShowapiRequest("http://route.showapi.com/341-1",my_appId,"my_appSecret")
res.AddTextPara("page","1")
res.AddTextPara("maxResult","20")
//res.AddFilePara("img", "C:\\Users\\showa\\Desktop\\使用过的\\4.png")//文件上传时设置
fmt.Println(res.Post())
# python3.6.5
# 需要引入requests包 :运行终端->进入python/Scripts ->输入:pip install requests
from ShowapiRequest import ShowapiRequest
r = ShowapiRequest("http://route.showapi.com/341-1","my_appId","my_appSecret" )
r.addBodyPara("page", "1")
r.addBodyPara("maxResult", "20")
# r.addFilePara("img", r"C:\Users\showa\Desktop\使用过的\4.png") #文件上传时设置
res = r.post()
print(res.text) # 返回信息