Update index.php

This commit is contained in:
zhxy-CN 2022-10-03 10:35:34 +08:00
parent 3c4a006269
commit afb5b6346a
Signed by: zhxycn
GPG Key ID: CC305996B88B3C03

View File

@ -1,31 +1,29 @@
<?php
$ago = '0'; // 时间 (几天前。0为今天1为昨天2为前天以此类推。)
$region = '1'; // 位置必应国际版填0国内版填1。
// 必应国内版当日16至次日16时为一张壁纸。
// GitHub: https://github.com/zhxycn/BingWallpaperAPI
$ago = '0'; //How many days ago
$region = '0'; //Bing region
if ($_GET['region'] == 'global') {
$region = '0';
} elseif ($_GET['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 ($_GET['encode'] == 'json') {
$echo = array('date' => $date, 'url' => $url, 'copyright' => $copyright);
echo json_encode($echo);
} else {
header("Location:$url");
}
$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");
}
?>