forked from mengkunsoft/wallpaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
58 lines (49 loc) · 2.03 KB
/
api.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
//tags http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome
//new http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByOrder&order=create_time&start=【0开始】&count=【加载数】&from=360chrome
//专区 http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid=【分类ID】&start=【0开始】&count=【加载数】&from=360chrome
$cid = getParam('cid', '360new');
switch($cid)
{
case '360new': // 360壁纸 新图片
$start = getParam('start', 0);
$count = getParam('count', 10);
echojson(file_get_contents("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByOrder&order=create_time&start={$start}&count={$count}&from=360chrome"));
break;
case '360tags':
echojson(file_get_contents("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome"));
break;
case 'bing':
$start = getParam('start', -1);
$count = getParam('count', 8);
echojson(file_get_contents("http://cn.bing.com/HPImageArchive.aspx?format=js&idx={$start}&n={$count}"));
break;
default:
$start = getParam('start', 0);
$count = getParam('count', 10);
echojson(file_get_contents("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={$cid}&start={$start}&count={$count}&from=360chrome"));
}
/**
* 获取GET或POST过来的参数
* @param $key 键值
* @param $default 默认值
* @return 获取到的内容(没有则为默认值)
*/
function getParam($key,$default='')
{
return trim($key && is_string($key) ? (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default)) : $default);
}
/**
* 输出一个json或jsonp格式的内容
* @param $data 数组内容
*/
function echojson($data)
{
header('Content-type: application/json');
$callback = getParam('callback');
if($callback != '') {//输出jsonp格式
die(htmlspecialchars($callback).'('.$data.')');
} else {
die($data);
}
}