1 Star 0 Fork 0

宇天行/天行数据

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
news.php 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
宇天行 提交于 2019-03-04 11:21 . 增加调用示例
<?php
header("Content-Type: text/html; charset=utf-8");
$num = 20; //返回数量
$url = 'http://api.tianapi.com/wxnew/?key=您的APIKEY&num='.$num.'&rand'; //API接口
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// var_dump(json_decode($file_contents ));
$json = json_decode($file_contents,true);
if($json['code'] == 200){
$txapi=$json['newslist'];
for ($i = 0; $i < $num; $i++){
// echo var_dump($de_json);
$title = $txapi[$i]['title']; //文章标题
$desc = $txapi[$i]['description']; //文章描述
$pic = $txapi[$i]['picUrl']; //封面图片
$url = $txapi[$i]['url']; //文章链接
echo $title."<br/>".$desc."<br/>".$pic."<br/>".$url."<br/>";
}
}else{
echo "返回错误,状态消息:".$json['msg'];
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/huceo/tianapi.git
git@gitee.com:huceo/tianapi.git
huceo
tianapi
天行数据
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385