接口地址:http://api.avatardata.cn/WorldNews/Query |
---|
返回格式:json/xml |
请求方式:get/post |
请求示例:http://api.avatardata.cn/WorldNews/Query?key=[您申请的APPKEY]&page=1&rows=10 |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
key | String | 必填 | 应用APPKEY |
rows | Int | 必填 | 返回记录条数,默认rows=20,最大50 |
page | Int | 必填 | 请求页数,默认page=1 |
dtype | String | 选填 | 返回结果格式:可选JSON/XML,默认为JSON |
format | Boolean | 选填 | 当返回结果格式为JSON时,是否对其进行格式化,为了节省流量默认为false,测试时您可以传入true来熟悉返回内容 |
名称 | 类型 | 说明 |
---|---|---|
参考JSON返回示例 | - | - |
{
"error_code": 0,
"reason": "Succes",
"result": [{
"ctime": "2015-10-21 13:52",
"title": "美前总统特别助理包道格:中美关系可能会不好",
"description": "美前总统特别助理包道格:中美关系可能会不好...",
"picUrl": "http://photocdn.sohu.com/20151021/Img423793409_ss.jpg",
"url": "http://news.sohu.com/20151021/n423793408.shtml"
},
{
"ctime": "2015-10-21 13:38",
"title": "日媒:只有印度和中国作出努力才能消除亚洲雾霾",
"description": "日媒:只有印度和中国作出努力才能消除亚洲雾霾...",
"picUrl": "http://photocdn.sohu.com/20151021/Img423792715_ss.jpg",
"url": "http://news.sohu.com/20151021/n423792311.shtml"
}
]
}
错误码 | 说明 |
---|---|
0 | 请求成功 |
1 | 参数错误 |
10001 | 错误的请求KEY |
10002 | 该KEY无请求权限 |
10003 | KEY过期 |
10004 | 错误的OPENID |
10005 | 应用未审核超时,请提交认证 |
10006 | 未知的请求源 |
10007 | 被禁止的IP |
10008 | 被禁止的KEY |
10009 | 当前IP请求超过限制 |
10010 | 请求超过次数限制,请购买套餐 |
10011 | 账户余额不足,请充值 |
10012 | 测试KEY超过请求限制 |
10013 | 请求错误,请重试 |
10014 | 接口维护 |
10015 | 接口停用 |
10016 | 当日调用次数到达上限,请明日重试或联系我们申请更多上限次数 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/3/15 17:50
*/
//----------------------------------
// 阿凡达数据 国际新闻 调用类
//----------------------------------
class freeApi{
private $apiUrl = 'http://api.avatardata.cn/WorldNews/Query?key=[您申请的APPKEY]&page=1&rows=10';
/**
* 将JSON内容转为数据,并返回
* @param string $content [内容]
* @return array
*/
public function returnArray($content){
return json_decode($content,true);
}
/**
* 获取 国际新闻 结果
* @return array
*/
public function getResult(){
return $this->returnArray($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 , 'free-api' );
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;
}
}