{ "showapi_res_code": 0, "showapi_res_error": "", "showapi_res_body": { "allNum": 2903, "allPages": 146, "contentlist": [{ "ct": "2015-07-30 01:10:29.995", "img": "http://img5.hao123.com/data/3_2ec986ed8d235ebb3bd562ed5b782eb6_0", "title": "起来!就不~~~", "type": 2 }], "currentPage": 1, "maxResult": 20 } }
public static void main(String path[]) throws Exception { URL u = new URL("http://route.showapi.com/341-2?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-2'; 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-2",//你要调用的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-2",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-2","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) # 返回信息