本文头图为 Bing 搜索引擎2021年2月8日的背景图。

Code

<?php
//判断是否随机调用
if ($_GET['rand']==='true') {
$gettime = rand(-1,7);
}
else {
//若不为随机调用则判断是否指定日期,若不指定默认为当日
$gettimebase = $_GET['day'];
if (empty($gettimebase)) {
$gettime = 0;
}
else {
$gettime = $gettimebase;
}
}
//获取Bing Json信息
$json_string = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx='.$gettime.'&n=1');
//转换为PHP数组
$data = json_decode($json_string);
//提取基础url
$imgurlbase = "https://cn.bing.com".$data->{"images"}[0]->{"urlbase"};
//判断是否指定图片大小
$imgsizebase = $_GET['size'];
if (empty($imgsizebase)){
    $imgsize = "1920x1080";
}
else {
    $imgsize = $imgsizebase;
}
//建立完整url
$imgurl = $imgurlbase."_".$imgsize.".jpg";
//获取其他信息
$imgtime = $data->{"images"}[0]->{"startdate"};
$imgtitle = $data->{"images"}[0]->{"copyright"};
$imglink = $data->{"images"}[0]->{"copyrightlink"};
//判断是否只获取图片信息
if ($_GET['info']==='true') {
    echo "{title:".$imgtitle.",url:".$imgurl.",link:".$imglink.",time:".$imgtime."api author:Otstar,api author link:https://angustar.com"."}";
}
else {
//若不是则跳转url
    header("Location: $imgurl");
}

调用方法

此API只支持 https 调用

所有参数均仅适用于以 GET 方式进行请求

直接插入 img 标签中

请求地址

https://angustar.tech/api/bing

调用参数

参数代码 参数含义 可用参数
rand 是否随机显示最近8天内的图片 true or Do not fill in
day 显示指定的最近图片 0,1,2,3,4,5,6,7(0为今天,1为昨天,以此类推)
size 指定获取图片大小 详见下方可用分辨率
info 获取图片基础信息(json 格式) true or Do not fill in

以上所有参数均非必要,默认参数为rand=falseday=0size=1920×1080info=false

可用分辨率:

  • 1920×1080
  • 1366×768
  • 1280×768
  • 1024×768
  • 800×600
  • 800×480
  • 768×1280
  • 720×1280
  • 640×480
  • 480×800
  • 400×240
  • 320×240
  • 240×320

中间的x为英文字母 x

调用示例

默认调用

不带任何参数调用:https://angustar.tech/api/bing

随机调用:rand=true

调用链接:https://angustar.tech/api/bing?rand=true

获取图片基础信息:info=true

调用链接:https://angustar.tech/api/bing?info=true

{title:拍摄于俄勒冈州海岸拥抱点瀑布的幻月 (© Ben Coffman/Tandem Stills + Motion),url:https://cn.bing.com/th?id=OHR.MoonDogs_ZH-CN5201314184_1920x1080.jpg,link:https://www.bing.com/search?q=%E5%B9%BB%E6%9C%88&form=hpcapt&mkt=zh-cn,time:20210208api author:Otstar,api author link:https://angustar.com}
最后修改:2021 年 08 月 23 日 01 : 06 PM
如果觉得我的文章对你有用,请随意赞赏