代码拉取完成,页面将自动刷新
<?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'];
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。