必应每日壁纸接口分享:一行代码给网站加自动更新背景
一、核心代码(PHP 缓存版)
新建xxx.php文件,粘贴以下代码放网站根目录
<?php
$cacheFile = 'bing_wallpaper_cache.txt';
$today = date('Ymd');
if (!file_exists($cacheFile) || substr(file_get_contents($cacheFile),0,8) != $today) {
$api = 'https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN';
$imgUrl = 'https://cn.bing.com' . preg_replace('/&w=\d+&h=\d+/','',json_decode(file_get_contents($api),true)['images'][0]['url']);
file_put_contents($cacheFile, $today.$imgUrl, LOCK_EX);
}
ob_clean();
header('Location: '.substr(file_get_contents($cacheFile),8));
exit;
?>二、使用方法
<style>body{background:url(https://xu219.cn/xxx.php) center fixed;background-size:cover;}</style>

还没有评论,来说两句吧...