File size: 1,032 Bytes
930f9b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
    exit('PHP 版本不得低于 5.2.0,可你正在使用的是 ' . PHP_VERSION);
}

function search($daysAgoQuery, $sizeQuery)
{
    if ($_GET["daysago"] != null) {
        $data = req($daysAgoQuery);
    } else {
        $data = req(0);
    }
    return "https://cn.bing.com" . $data['images'][0]['urlbase'] . "_" . $sizeQuery . ".jpg";
}

function req($daysAgo)
{
    return json_decode(file_get_contents("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=" . $daysAgo . "&n=1"), true);
}

$sizeEnum = array(
    '1920x1200',
    '1920x1080',
    '1366x768',
    '1280x768',
    '1024x768',
    '800x600',
    '800x480',
    '768x1280',
    '720x1280',
    '640x480',
    '480x800',
    '400x240',
    '320x240',
    '240x320'
);

$sizeQuery = $_GET["size"] != null && in_array($_GET["size"], $sizeEnum) ? $_GET["size"] : "1920x1080";
$daysAgoQuery = $_GET["daysago"];
$url = search($daysAgoQuery, $sizeQuery);
header("status: 302");
header("Location: $url");
die();