获取财经新闻
<?php
function fetchData(){
$time = time();
if(file_exists("zixun")){
$zixun = file_get_contents("zixun");
$zixun = json_decode($zixun,true);
if($time > $zixun["time"]){
return $zixun;
}
}
$url="https://zhibo.sina.com.cn/api/zhibo/feed?zhibo_id=152&tag_id=10&page_size=100";
$con = curl_init((string)$url);
curl_setopt($con, CURLOPT_HEADER, false);
curl_setopt($con, CURLOPT_RETURNTRANSFER,true);
curl_setopt($con, CURLOPT_TIMEOUT, (int)$timeout);
curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($con, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($con);
$data = json_decode($data,true);
$data = ($data["result"]["data"]["feed"]["list"]);
$zixun = [
"list"=>$data,
"time"=>$time+1000*60*5
];
file_put_contents("zixun",json_encode($zixun));
return $zixun;
}
$data = fetchData();
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header('Access-Control-Allow-Headers:x-requested-with,content-type');
header('content-type:text/json;charset=utf-8');
echo json_encode($data);

浙公网安备 33010602011771号