@沉沦老师批的作业
<?php
/*
* @Author: Qicloud
* @Date: 2020-09-24 14:47:29
* @Title: Bing
* @Project: 背景图API
* @QQ: 66547997
* @我想你们的努力一定会有回报的
*/
$time = date("Ymd", time());
$log = "./log/" . $time . '.txt';
//判断缓存文件是否存在
if (file_exists($log)) {
//读取缓存
$imgurl = file_get_contents($log);
//跳转至图片地址
header("Location: $imgurl");
} else {
//获取bing背景图
$str = file_get_contents('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
//解析Bing官方接口Json
$data = json_decode($str,true);
//七牛CDN镜像加速
$imgurl = 'http://s.cn.bing.net'.$data['images'][0]['urlbase']. '_1920x1080.jpg';
//写入TXT用作缓存
file_put_contents($log, $imgurl);
//跳转至图片地址
header("Location: $imgurl");
}
应该,我这个是目前优化最好的Bing每日一图api(大佬勿喷)