精华0
阅读权限250
最后登录2026-11-28
在线时间72 小时

总版主
名望- 0 点
星币- 13633 枚
星辰- 0 颗
好评- 1 点
|
注册登录后全站资源免费查看下载
您需要 登录 才可以下载或查看,没有账号?立即注册
×
相比旧颜的这个更仔细,不是说什么挑衅之类的。
反正没什么技术含量,只不过比较适合萌新学习毕竟易懂。
- <?php
header('Access-Control-Allow-Origin:*');
header('Content-Type:text/json;charset=utf8');
/**
* @name 蓝优
* 幽梦数据 https://umqun.com/
**/
$api = myCurl('https://3g.dxy.cn/newh5/view/pneumonia_timeline?whichFrom=dxy');
/*实时播报*/
$One = 'window.getTimelineService =';
$Two = '}catch(e)';
$real = GetBetween($api,$One,$Two);
$data = json_decode($real,true);
foreach ($data as $dxy){
$value[] = array(
'date'=>$dxy["pubDateStr"],
'title'=>$dxy["title"],
'des'=>$dxy["summary"],
'source'=>$dxy["infoSource"]
);
}
/*全国例数*/
$One = 'window.getAreaStat =';
$Two = '}catch(e)';
$routine = GetBetween($api,$One,$Two);
$data1 = json_decode($routine,true);
foreach ($data1 as $dxy){
$cities = $dxy["cities"];
$value1[] = array(
'name'=>$dxy["provinceName"],//省份
'conf'=>$dxy["confirmedCount"],//确诊
'cured'=>$dxy["curedCount"],//治愈
'source'=>$dxy["deadCount"], //死亡
'cities'=>$cities //市级
);
}
/*数组*/
$json = array('data'=>$value,'list'=>$value1);
/*输出*/
echo json_encode($json,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
/**
*cityName:市级
*confirmedCount:确诊
*curedCount:治愈
*deadCount:死亡
**/
/**
* @Return string
* 截取ID
**/
function GetBetween($content,$start,$end) {
$r = explode($start, $content);
if (isset($r[1])) {
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
/**
* @Return string
* Curl GET
**/
function myCurl($url){
$ch = curl_init(); // Curl 初始化
$timeout = 30; // 超时时间:30s
$ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'; // 伪造抓取 UA
$ip = mt_rand(11, 191) . "." . mt_rand(0, 240) . "." . mt_rand(1, 240) . "." . mt_rand(1, 240);
curl_setopt($ch, CURLOPT_URL, $url); // 设置 Curl 目标
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Curl 请求有返回的值
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置抓取超时时间
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 跟踪重定向
curl_setopt($ch, CURLOPT_REFERER, $url); // 伪造来源网址
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip)); //伪造IP
curl_setopt($ch, CURLOPT_USERAGENT, $ua); // 伪造ua
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //强制协议为1.0
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); //强制使用IPV4协议解析域名
$content = curl_exec($ch);
curl_close($ch); // 结束 Curl
return $content; // 函数返回内容
}
复制代码
|
|