<?php/*
功能:自动调取壁纸作为网站背景
开发时间:2017年7月4日
应用案例:https://www.68xi.cn/search/
分享三个在线壁纸调用接口
tags http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome
new http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByOrder&order=create_time&start=【0开始】&count=【加载数】&from=360chrome
专区 http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid=【分类ID】&start=【0开始】&count=【加载数】&from=360chrome
*/
@header('Content-Type: application/json; charset=UTF-8');
$number=-1;
$url = 'http://cn.bing.com/HPImageArchive.aspx?format=js&idx=6&n=1';//必应壁纸调取接口
$curl = curl_init();
$httpheader[] = "Accept:/";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$bing_data = curl_exec($curl);
curl_close($curl);
$bing_arr=json_decode($bing_data,true);
if (!empty($bing_arr'images'['url'])) {
$data['code']=1;
$data['url']='https://cn.bing.com'.$bing_arr['images'][0]['url'];
if(checkmobile()==true)$data['url']=str_replace('1920x1080','768x1366',$data['url']);
}else{
$data['code']=-1;
}
exit(json_encode($data));
function strexists($string, $find) {
return !(strpos($string, $find) === FALSE);
}
function dstrpos($string, $arr) {
if(empty($string)) return false;
foreach((array)$arr as $v) {
if(strpos($string, $v) !== false) {
return true;
}
}
return false;
}
function checkmobile() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
$ualist = array('android', 'midp', 'nokia', 'mobile', 'iphone', 'ipod', 'blackberry', 'windows phone');
if((dstrpos($useragent, $ualist) || strexists($_SERVER['HTTP_ACCEPT'], "VND.WAP") || strexists($_SERVER['HTTP_VIA'],"wap"))){
return true;
}else{
return false;
}
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询