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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| <?php
error_reporting(0); header("Access-Control-Allow-Origin:*"); header("Content-type:application/json; charset=utf-8"); date_default_timezone_set("Asia/Shanghai");
class VvhanApi { public function zhihuHot() { $_resHtml = str_replace(["\n", "\r", " "], '', $this->vvhanCurl('https://www.zhihu.com/hot', ['User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'], 'https://www.zhihu.com')); preg_match('/<scriptid=\"js-initialData\"type=\"text\/json\">(.*?)<\/script>/', $_resHtml, $_resHtmlArr); $jsonRes = json_decode($_resHtmlArr[1], true); $tempArr = []; foreach ($jsonRes['initialState']['topstory']['hotList'] as $k => $v) { array_push($tempArr, [ 'index' => $k + 1, 'title' => $v['target']['titleArea']['text'], 'desc' => $v['target']['excerptArea']['text'], 'pic' => $v['target']['imageArea']['url'], 'hot' => $v['target']['metricsArea']['text'], 'url' => $v['target']['link']['url'], 'mobilUrl' => $v['target']['link']['url'] ]); } return [ 'success' => true, 'title' => '知乎热榜', 'subtitle' => '热度', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; }
public function wbresou() { $_md5 = md5(time()); $cookie = "Cookie: {$_md5}:FG=1"; $jsonRes = json_decode($this->vvhanCurl('https://weibo.com/ajax/side/hotSearch', null, $cookie, "https://s.weibo.com"), true); $tempArr = []; foreach ($jsonRes['data']['realtime'] as $k => $v) { array_push($tempArr, [ 'index' => $k + 1, 'title' => $v['note'], 'hot' => $v['num'] . '万', 'url' => "https://s.weibo.com/weibo?q={$v['word_scheme']}&t=31&band_rank=12&Refer=top", 'mobilUrl' => "https://s.weibo.com/weibo?q={$v['word_scheme']}&t=31&band_rank=12&Refer=top" ]); } return [ 'success' => true, 'title' => '微博', 'subtitle' => '热搜榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; }
public function baiduredian() { $_resHtml = str_replace(["\n", "\r", " "], '', $this->vvhanCurl('https://top.baidu.com/board?tab=realtime', null)); preg_match('/<!--s-data:(.*?)-->/', $_resHtml, $_resHtmlArr); $jsonRes = json_decode($_resHtmlArr[1], true); return $jsonRes; $tempArr = []; foreach ($jsonRes['data']['cards'] as $v) { foreach ($v['content'] as $k => $_v) { array_push($tempArr, [ 'index' => $k + 1, 'title' => $_v['word'], 'desc' => $_v['desc'], 'pic' => $_v['img'], 'url' => $_v['url'], 'hot' => $_v['hotScore'] . 'W个内容', 'mobilUrl' => $_v['appUrl'] ]); } } return [ 'success' => true, 'title' => '百度热点', 'subtitle' => '指数', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; }
private function vvhanCurl($url, $header = [ "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Encoding: gzip, deflate, br", "Accept-Language: zh-CN,zh;q=0.9", "Connection: keep-alive", "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1" ], $cookie = null, $refer = 'https://www.baidu.com') { $ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255); $header[] = "CLIENT-IP:" . $ip; $header[] = "X-FORWARDED-FOR:" . $ip; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_REFERER, $refer); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $output = curl_exec($ch); curl_close($ch); return $output; } }
$_type = isset($_GET['type']) ? $_GET['type'] : ''; $API = new VvhanApi;
switch ($_type) { case 'baidu': $_res = $API->baiduredian(); break; case 'zhihu': $_res = $API->zhihuHot(); break;
case 'weibo': $_res = $API->wbresou(); break;
default: $_res = ['success' => false, 'message' => '参数不完整']; break; } $_res['copyright'] = '韩小韩博客 www.vvhan.com'; exit(json_encode($_res, JSON_UNESCAPED_UNICODE)); ?>
|