BingWallpaperAPI/index.php

30 lines
1003 B
PHP
Raw Permalink Normal View History

2022-02-27 07:20:48 +00:00
<?php
2022-10-03 02:35:34 +00:00
// GitHub: https://github.com/zhxycn/BingWallpaperAPI
$ago = '0'; //How many days ago
$region = '0'; //Bing region
2022-06-13 13:23:31 +00:00
2022-10-03 02:35:34 +00:00
$ago = $_REQUEST['ago'];
if ($_REQUEST['region'] == 'global') {
$region = '0';
} elseif ($_REQUEST['region'] == 'cn') {
$region = '1';
} else {
$region = $region;
}
if ($region == '0') {
$data = json_decode(file_get_contents('https://bing.com/HPImageArchive.aspx?format=js&idx=' . $ago . '&n=1'), true);
$url = "https://bing.com" . $data['images'][0]['url'];
} elseif ($region == '1') {
$data = json_decode(file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=' . $ago . '&n=1&mkt=zh-CN'), true);
$url = "https://cn.bing.com" . $data['images'][0]['url'];
}
$date = $data['images'][0]['startdate'];
$copyright = $data['images'][0]['copyright'];
if ($_REQUEST['encode'] == 'json') {
$echo = array('date' => $date, 'url' => $url, 'copyright' => $copyright);
echo json_encode($echo);
} else {
header("Location:$url");
}
2022-02-27 07:20:48 +00:00
?>