接口地址:https://api.apiopen.top/getJoke |
---|
返回格式:json |
请求方式:get/post |
请求示例:https://api.apiopen.top/getJoke?page=1&count=2&type=video |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
type | String | 必填 | 指定查询类型,可选参数(all/video/image/gif/text) |
page | String | 选填 | 页码(传0或者不传会随机推荐) |
count | String | 选填 | 每页返回数量 |
名称 | 类型 | 说明 |
---|---|---|
code | int | 状态码 |
message | string | 提示消息 |
result | array | 结果集合 |
{
"code": 200,
"message": "成功!",
"result": [{
"sid": "29601022",
"text": "哈哈哈原谅我不厚道的笑了",
"type": "video",
"thumbnail": "http://wimg.spriteapp.cn/picture/2019/0617/205fb4bc-90e3-11e9-96bf-1866daeb0df1_wpd.jpg",
"video": "http://wvideo.spriteapp.cn/video/2019/0617/205fb4bc-90e3-11e9-96bf-1866daeb0df1_wpd.mp4",
"images": null,
"up": "95",
"down": "6",
"forward": "1",
"comment": "8",
"uid": "20746551",
"name": "温柔尝尽了吗",
"header": "http://wimg.spriteapp.cn/profile/large/2019/03/26/5c99f6e152ea2_mini.jpg",
"top_comments_content": "人没事就万幸了,听话女士,以后不要碰车了,不管四个轮还是两个轮的",
"top_comments_voiceuri": "",
"top_comments_uid": "20782663",
"top_comments_name": "拾歡7XE",
"top_comments_header": "http://wx.qlogo.cn/mmopen/2EzJggZltBP54y2zB04fSVESdBB1DicpJuJSRhGAUUmvxvrypibvHOt3DpSqLUdic917kZzVppAbO7o45bI7jHhfOQDmLF4EBHt/0",
"passtime": "2001-06-19 02:51:01"
}]
}
错误码 | 说明 |
---|---|
400 | 参数错误 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/3/15 17:50
*/
//----------------------------------
// peakchao 调用类
//----------------------------------
class freeApi{
private $apiUrl = 'https://api.apiopen.top/getJoke?page=1&count=1&type=video';
/**
* 获取 结果
* @return array
*/
public function getResult(){
return $this->freeApiCurl($this->apiUrl);
}
/**
* 请求接口返回内容
* @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;
}
}
$res = new freeApi();
var_dump($res->getResult());