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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| <?php
$proxy_url = "tcp://[fe80::1%eth0]:8888";
$cid = getParam('cid', '360new');
switch($cid) { case '360new': $start = getParam('start', 0); $count = getParam('count', 10); $url = "http://wp.birdpaper.com.cn/intf/newestList?pageno={$start}&count={$count}"; echojson(fetchData($url, $proxy_url)); break;
case '360tags': $url = "http://wp.birdpaper.com.cn/intf/getCategory"; echojson(fetchData($url, $proxy_url)); break; case 'bing': $start = getParam('start', -1); $count = getParam('count', 8); $url = "http://cn.bing.com/HPImageArchive.aspx?format=js&idx={$start}&n={$count}"; echojson(fetchData($url, $proxy_url)); break; case '360search': $content = getParam('content', ''); $start = getParam('start', 0); $count = getParam('count', 10); $url = "http://wp.birdpaper.com.cn/intf/search?content={$content}&pageno={$start}&count={$count}"; echojson(fetchData($url, $proxy_url)); break; default: $start = getParam('start', 0); $count = getParam('count', 10); $url = "http://wp.birdpaper.com.cn/intf/GetListByCategory?cids={$cid}&pageno={$start}&count={$count}"; echojson(fetchData($url, $proxy_url)); }
function fetchData($url, $proxy) { $opts = [ "http" => [ "proxy" => $proxy, "request_fulluri" => true, "timeout" => 10, "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\r\n" ] ]; $context = stream_context_create($opts); $result = @file_get_contents($url, false, $context); if ($result === false) { return json_encode(["error" => "无法连接远程服务器", "debug_url" => $url]); } return $result; }
function getParam($key, $default='') { return trim($key && is_string($key) ? (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default)) : $default); }
function echojson($data) { header('Content-Type: application/json; charset=utf-8'); echo $data; }
|