聚合熱搜熱榜PHP接口API源碼,本源碼接口均抓取采集各大官網(wǎng)數(shù)據(jù)。
PHP環(huán)境為5.6或以上,解壓壓縮包里面的hotlist.php文件到網(wǎng)站目錄
然后輸入?yún)?shù)輸入?type
參數(shù)內(nèi)容:
zhihu
(知乎熱榜) weibo
(微博熱搜) baidu
(百度熱點) history
(歷史上的今天) bilihot
(嗶哩嗶哩熱搜) biliall
(嗶哩嗶哩全站日榜) sspai
(少數(shù)派頭條) douyin
(抖音熱搜) CSDN
(CSDN頭條榜)
使用方法
訪問你的 域名地址/hotlist.php?type=
?type=
(輸入?yún)?shù)才能顯示內(nèi)容)
示例:
訪問你的 域名地址/hotlist.php?type=zhihu
API源碼
<?php header("Access-Control-Allow-Origin:*"); header("Content-type:application/json; charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); class Api { // 少數(shù)派 熱榜 public function sspai() { $jsonRes = json_decode($this->Curl('https://sspai.com/api/v1/article/tag/page/get?limit=100000&tag=%E7%83%AD%E9%97%A8%E6%96%87%E7%AB%A0', null, null, "https://sspai.com"), true); $tempArr = []; foreach ($jsonRes['data'] as $k => $v) { array_push($tempArr, [ 'index' => $k +1, 'title' => $v['title'], 'createdAt' => date('Y-m-d', $v['released_time']), 'other' => $v['author']['nickname'], 'like_count' => $v['like_count'], 'comment_count' => $v['comment_count'], 'url' => 'https://sspai.com/post/'.$v['id'], 'mobilUrl' => 'https://sspai.com/post/'.$v['id'] ]); } return [ 'success' => true, 'title' => '少數(shù)派', 'subtitle' => '熱榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // CSDN 頭條榜 public function csdn() { $_resHtml = $this->Curl('https://www.csdn.net', null, "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", "https://www.csdn.net"); preg_match('/window.__INITIAL_STATE__=(.*?);<\/script>/', $_resHtml, $_resHtmlArr); $jsonRes = json_decode($_resHtmlArr[1],true); $tempArr = []; //頭條 foreach ($jsonRes['pageData']['data']['Headimg'] as $k => $v) { array_push($tempArr, [ 'index' => $k +1, 'title' => $v['title'], 'url' => $v['url'], 'mobilUrl' => $v['url'] ]); } //頭條1 foreach ($jsonRes['pageData']['data']['www-Headlines'] as $k => $v) { array_push($tempArr, [ 'index' => $k +17, 'title' => $v['title'], 'url' => $v['url'], 'mobilUrl' => $v['url'] ]); } //頭條2 foreach ($jsonRes['pageData']['data']['www-headhot'] as $k => $v) { array_push($tempArr, [ 'index' => $k +48, 'title' => $v['title'], 'url' => $v['url'], 'mobilUrl' => $v['url'] ]); } return [ 'success' => true, 'title' => 'CSDN', 'subtitle' => '頭條榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } //百度百科 歷史上的今天 public function history() { $month=date('m',time() ); $day=date('d',time() ); //當(dāng)前年月日 $today = date('Y年m月d日'); //獲取接口數(shù)據(jù) $jsonRes = json_decode($this->Curl('https://baike.baidu.com/cms/home/eventsOnHistory/'.$month.'.json', null, null, "https://baike.baidu.com"), true); $tempArr = []; //統(tǒng)計當(dāng)日總數(shù) $countnum = count($jsonRes[$month][$month.$day])-1; foreach ($jsonRes[$month][$month.$day] as $k => $v) { array_push($tempArr, [ 'index' => $k +1, 'title' => $v['year'].'年-'.strip_tags($v['title']), 'url' => 'https://www.douyin.com/search/'.urlencode($v['title']), 'mobilUrl' => 'https://www.douyin.com/search/'.urlencode($v['title']) ]); } return [ 'success' => true, 'title' => '百度百科', 'subtitle' => '歷史上的今天', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // 抖音 熱搜榜 public function douyin() { $jsonRes = json_decode($this->Curl('https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/word/', null, null, "https://www.douyin.com"), true); $tempArr = []; foreach ($jsonRes['word_list'] as $k => $v) { array_push($tempArr, [ 'index' => $k +1, 'title' => $v['word'], 'hot' => round($v['hot_value']/10000,1).'萬', 'url' => 'https://www.douyin.com/search/'.urlencode($v['word']), 'mobilUrl' => 'https://www.douyin.com/search/'.urlencode($v['word']) ]); } return [ 'success' => true, 'title' => '抖音', 'subtitle' => '熱搜榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // 嗶哩嗶哩 全站日榜 public function bilibili_rankall() { $jsonRes = json_decode($this->Curl('https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all', null, null, "https://www.bilibili.com"), true); $tempArr = []; foreach ($jsonRes['data']['list'] as $k => $v) { array_push($tempArr, [ 'index' => $k +1, 'title' => $v['title'], 'pic' => $v['pic'], 'desc' => $v['desc'], 'hot' => round($v['stat']['view']/10000,1).'萬', 'url' => $v['short_link'], 'mobilUrl' => $v['short_link'] ]); } return [ 'success' => true, 'title' => '嗶哩嗶哩', 'subtitle' => '全站日榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // 嗶哩嗶哩 熱搜榜 public function bilibili_hot() { $jsonRes = json_decode($this->Curl('https://app.bilibili.com/x/v2/search/trending/ranking', null, null, "https://www.bilibili.com"), true); $tempArr = []; //return $jsonRes; foreach ($jsonRes['data']['list'] as $k => $v) { array_push($tempArr, [ 'index' => $v['position'], 'title' => $v['keyword'], 'url' => 'https://search.bilibili.com/all?keyword='.$v['keyword'].'&order=click', 'mobilUrl' => 'https://search.bilibili.com/all?keyword='.$v['keyword'].'&order=click' ]); } return [ 'success' => true, 'title' => '嗶哩嗶哩', 'subtitle' => '熱搜榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // 知乎熱榜 熱度 public function zhihuHot() { $jsonRes = json_decode($this->Curl('https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true', null, null, "https://www.zhihu.com"), true); $tempArr = []; foreach ($jsonRes['data'] as $k => $v) { preg_match('/\d+/', $v['detail_text'], $hot); array_push($tempArr, [ 'index' => $k + 1, 'title' => $v['target']['title'], 'hot' => $hot[0].'萬', 'url' => 'https://www.zhihu.com/question/'.urlencode($v['target']['id']), 'mobilUrl' => 'https://www.zhihu.com/question/'.urlencode($v['target']['id']) ]); } 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->Curl('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' => round($v['num']/10000,1).'萬', 'url' => "https://s.weibo.com/weibo?q=".$v['note']."&Refer=index", 'mobilUrl' => "https://s.weibo.com/weibo?q=".$v['note']."&Refer=index" ]); } return [ 'success' => true, 'title' => '微博', 'subtitle' => '熱搜榜', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } // 百度熱點 指數(shù) public function baiduredian() { $_resHtml = str_replace(["\n", "\r", " "], '', $this->Curl('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' => round($_v['hotScore']/10000,1).'萬', 'mobilUrl' => $_v['appUrl'] ]); } } return [ 'success' => true, 'title' => '百度熱點', 'subtitle' => '指數(shù)', 'update_time' => date('Y-m-d h:i:s', time()), 'data' => $tempArr ]; } private function Curl($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); //設(shè)置傳輸?shù)?nbsp;url curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //發(fā)送 http 報頭 curl_setopt($ch, CURLOPT_COOKIE, $cookie); //設(shè)置Cookie curl_setopt($ch, CURLOPT_REFERER, $refer); //設(shè)置Referer curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); // 解碼壓縮文件 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 對認(rèn)證證書來源的檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 從證書中檢查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 設(shè)置超時限制防止死循環(huán) $output = curl_exec($ch); curl_close($ch); return $output; } } $_type = isset($_GET['type']) ? $_GET['type'] : ''; $API = new Api; switch ($_type) { case 'baidu': $_res = $API->baiduredian(); break; case 'zhihu': $_res = $API->zhihuHot(); break; case 'weibo': $_res = $API->wbresou(); break; case 'bilihot': $_res = $API->bilibili_hot(); break; case 'biliall': $_res = $API->bilibili_rankall(); break; case 'douyin': $_res = $API->douyin(); break; case 'history': $_res = $API->history(); break; case 'csdn': $_res = $API->csdn(); break; case 'sspai': $_res = $API->sspai(); break; default: $_res = ['success' => false, 'message' => '參數(shù)不完整']; break; } $_res['copyright'] = '聚合熱搜榜'; exit(json_encode($_res,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT)); ?>