聚合热搜热榜PHP接口API源码

 3392

聚合热搜热榜PHP接口API源码,本源码接口均抓取采集各大官网数据。

PHP环境为5.6或以上,解压压缩包里面的hotlist.php文件到网站目录

然后输入参数输入?type

参数内容:

zhihu(知乎热榜)  weibo(微博热搜)  baidu(百度热点)  history(历史上的今天)  bilihot(哔哩哔哩热搜)  biliall(哔哩哔哩全站日榜)  sspai(少数派头条)  douyin(抖音热搜)  CSDN(CSDN头条榜) 

使用方法

访问你的 域名地址/hotlist.php?type=

?type=(输入参数才能显示内容)

示例:

访问你的 域名地址/hotlist.php?type=zhihu

API源码

  1. <?php
  2. header("Access-Control-Allow-Origin:*");
  3. header("Content-type:application/json; charset=utf-8");
  4. date_default_timezone_set("Asia/Shanghai");
  5. class Api
  6. {
  7.   // 少数派 热榜
  8.   public function sspai()
  9.   {
  10.     $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);
  11.     $tempArr = [];
  12.     foreach ($jsonRes['data'] as $k => $v) {
  13.       array_push($tempArr, [
  14.         'index' => $k +1,
  15.         'title' => $v['title'],
  16.         'createdAt' => date('Y-m-d', $v['released_time']),
  17.         'other' => $v['author']['nickname'],
  18.         'like_count' => $v['like_count'],
  19.         'comment_count' => $v['comment_count'],
  20.         'url' => 'https://sspai.com/post/'.$v['id'],
  21.         'mobilUrl' => 'https://sspai.com/post/'.$v['id']
  22.       ]);
  23.     }
  24.     return [
  25.       'success' => true,
  26.       'title' => '少数派',
  27.       'subtitle' => '热榜',
  28.       'update_time' => date('Y-m-d h:i:s', time()),
  29.       'data' => $tempArr
  30.     ];
  31.   }
  32.    
  33.   // CSDN 头条榜
  34.   public function csdn()
  35.   {
  36.     $_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");
  37.     preg_match('/window.__INITIAL_STATE__=(.*?);<\/script>/', $_resHtml, $_resHtmlArr);
  38.     $jsonRes = json_decode($_resHtmlArr[1],true);
  39.     $tempArr = [];
  40.     //头条
  41.     foreach ($jsonRes['pageData']['data']['Headimg'] as $k => $v) {
  42.       array_push($tempArr, [
  43.         'index' => $k +1,
  44.         'title' => $v['title'],
  45.         'url' => $v['url'],
  46.         'mobilUrl' => $v['url']
  47.       ]);
  48.     }
  49.     //头条1
  50.     foreach ($jsonRes['pageData']['data']['www-Headlines'] as $k => $v) {
  51.       array_push($tempArr, [
  52.         'index' => $k +17,
  53.         'title' => $v['title'],
  54.         'url' => $v['url'],
  55.         'mobilUrl' => $v['url']
  56.       ]);
  57.     }
  58.     //头条2
  59.     foreach ($jsonRes['pageData']['data']['www-headhot'] as $k => $v) {
  60.       array_push($tempArr, [
  61.         'index' => $k +48,
  62.         'title' => $v['title'],
  63.         'url' => $v['url'],
  64.         'mobilUrl' => $v['url']
  65.       ]);
  66.     }
  67.     return [
  68.       'success' => true,
  69.       'title' => 'CSDN',
  70.       'subtitle' => '头条榜',
  71.       'update_time' => date('Y-m-d h:i:s', time()),
  72.       'data' => $tempArr
  73.     ];
  74.   }
  75.    
  76.   //百度百科  历史上的今天
  77.   public function history()
  78.   {
  79.     $month=date('m',time() );
  80.     $day=date('d',time() );
  81.     //当前年月日
  82.     $today = date('Y年m月d日');
  83.     //获取接口数据
  84.     $jsonRes = json_decode($this->Curl('https://baike.baidu.com/cms/home/eventsOnHistory/'.$month.'.json', null, null, "https://baike.baidu.com"), true);
  85.     $tempArr = [];
  86.     //统计当日总数
  87.     $countnum = count($jsonRes[$month][$month.$day])-1;
  88.     foreach ($jsonRes[$month][$month.$day] as $k => $v) {
  89.       array_push($tempArr, [
  90.         'index' => $k +1,
  91.         'title' => $v['year'].'年-'.strip_tags($v['title']),
  92.         'url' => 'https://www.douyin.com/search/'.urlencode($v['title']),
  93.         'mobilUrl' => 'https://www.douyin.com/search/'.urlencode($v['title'])
  94.       ]);
  95.     }
  96.     return [
  97.       'success' => true,
  98.       'title' => '百度百科',
  99.       'subtitle' => '历史上的今天',
  100.       'update_time' => date('Y-m-d h:i:s', time()),
  101.       'data' => $tempArr
  102.     ];
  103.   }
  104.    
  105.   // 抖音 热搜榜
  106.   public function douyin()
  107.   {
  108.     $jsonRes = json_decode($this->Curl('https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/word/', null, null, "https://www.douyin.com"), true);
  109.     $tempArr = [];
  110.     foreach ($jsonRes['word_list'] as $k => $v) {
  111.       array_push($tempArr, [
  112.         'index' => $k +1,
  113.         'title' => $v['word'],
  114.         'hot' => round($v['hot_value']/10000,1).'万',
  115.         'url' => 'https://www.douyin.com/search/'.urlencode($v['word']),
  116.         'mobilUrl' => 'https://www.douyin.com/search/'.urlencode($v['word'])
  117.       ]);
  118.     }
  119.     return [
  120.       'success' => true,
  121.       'title' => '抖音',
  122.       'subtitle' => '热搜榜',
  123.       'update_time' => date('Y-m-d h:i:s', time()),
  124.       'data' => $tempArr
  125.     ];
  126.   }
  127.   // 哔哩哔哩 全站日榜
  128.   public function bilibili_rankall()
  129.   {
  130.     $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);
  131.     $tempArr = [];
  132.     foreach ($jsonRes['data']['list'] as $k => $v) {
  133.       array_push($tempArr, [
  134.         'index' => $k +1,
  135.         'title' => $v['title'],
  136.         'pic' => $v['pic'],
  137.         'desc' => $v['desc'],
  138.         'hot' => round($v['stat']['view']/10000,1).'万',
  139.         'url' => $v['short_link'],
  140.         'mobilUrl' => $v['short_link']
  141.       ]);
  142.     }
  143.     return [
  144.       'success' => true,
  145.       'title' => '哔哩哔哩',
  146.       'subtitle' => '全站日榜',
  147.       'update_time' => date('Y-m-d h:i:s', time()),
  148.       'data' => $tempArr
  149.     ];
  150.   }
  151.   // 哔哩哔哩 热搜榜
  152.   public function bilibili_hot()
  153.   {
  154.     $jsonRes = json_decode($this->Curl('https://app.bilibili.com/x/v2/search/trending/ranking', null, null, "https://www.bilibili.com"), true);
  155.     $tempArr = [];
  156.     //return $jsonRes;
  157.     foreach ($jsonRes['data']['list'] as $k => $v) {
  158.       array_push($tempArr, [
  159.         'index' => $v['position'],
  160.         'title' => $v['keyword'],
  161.         'url' => 'https://search.bilibili.com/all?keyword='.$v['keyword'].'&order=click',
  162.         'mobilUrl' => 'https://search.bilibili.com/all?keyword='.$v['keyword'].'&order=click'
  163.       ]);
  164.     }
  165.     return [
  166.       'success' => true,
  167.       'title' => '哔哩哔哩',
  168.       'subtitle' => '热搜榜',
  169.       'update_time' => date('Y-m-d h:i:s', time()),
  170.       'data' => $tempArr
  171.     ];
  172.   }
  173.    
  174.   // 知乎热榜  热度
  175.   public function zhihuHot()
  176.   {
  177.     $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);
  178.     $tempArr = [];
  179.     foreach ($jsonRes['data'] as $k => $v) {
  180.       preg_match('/\d+/',  $v['detail_text'], $hot);
  181.       array_push($tempArr, [
  182.         'index' => $k + 1,
  183.         'title' => $v['target']['title'],
  184.         'hot' => $hot[0].'万',
  185.         'url' => 'https://www.zhihu.com/question/'.urlencode($v['target']['id']),
  186.         'mobilUrl' => 'https://www.zhihu.com/question/'.urlencode($v['target']['id'])
  187.       ]);
  188.     }
  189.     return [
  190.       'success' => true,
  191.       'title' => '知乎热榜',
  192.       'subtitle' => '热度',
  193.       'update_time' => date('Y-m-d h:i:s', time()),
  194.       'data' => $tempArr
  195.     ];
  196.   }
  197.   // 微博 热搜榜
  198.   public function wbresou()
  199.   {
  200.     $_md5 = md5(time());
  201.     $cookie = "Cookie: {$_md5}:FG=1";
  202.     $jsonRes = json_decode($this->Curl('https://weibo.com/ajax/side/hotSearch', null, $cookie, "https://s.weibo.com"), true);
  203.     $tempArr = [];
  204.     foreach ($jsonRes['data']['realtime'] as $k => $v) {
  205.       array_push($tempArr, [
  206.         'index' => $k + 1,
  207.         'title' => $v['note'],
  208.         'hot' => round($v['num']/10000,1).'万',
  209.         'url' => "https://s.weibo.com/weibo?q=".$v['note']."&Refer=index",
  210.         'mobilUrl' => "https://s.weibo.com/weibo?q=".$v['note']."&Refer=index"
  211.       ]);
  212.     }
  213.     return [
  214.       'success' => true,
  215.       'title' => '微博',
  216.       'subtitle' => '热搜榜',
  217.       'update_time' => date('Y-m-d h:i:s', time()),
  218.       'data' => $tempArr
  219.     ];
  220.   }
  221.   // 百度热点 指数
  222.   public function baiduredian()
  223.   {
  224.     $_resHtml = str_replace(["\n", "\r", " "], '', $this->Curl('https://top.baidu.com/board?tab=realtime', null));
  225.     preg_match('/<!--s-data:(.*?)-->/', $_resHtml, $_resHtmlArr);
  226.     $jsonRes = json_decode($_resHtmlArr[1], true);
  227.     //return $jsonRes;
  228.     $tempArr = [];
  229.     foreach ($jsonRes['data']['cards'] as $v) {
  230.       foreach ($v['content'] as $k => $_v) {
  231.         array_push($tempArr, [
  232.           'index' => $k + 1,
  233.           'title' => $_v['word'],
  234.           'desc' => $_v['desc'],
  235.           'pic' => $_v['img'],
  236.           'url' => $_v['url'],
  237.           'hot' => round($_v['hotScore']/10000,1).'万',
  238.           'mobilUrl' => $_v['appUrl']
  239.         ]);
  240.       }
  241.     }
  242.     return [
  243.       'success' => true,
  244.       'title' => '百度热点',
  245.       'subtitle' => '指数',
  246.       'update_time' => date('Y-m-d h:i:s', time()),
  247.       'data' => $tempArr
  248.     ];
  249.   }
  250.   private function Curl($url, $header = [
  251.     "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",
  252.     "Accept-Encoding: gzip, deflate, br",
  253.     "Accept-Language: zh-CN,zh;q=0.9",
  254.     "Connection: keep-alive",
  255.     "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"
  256.   ], $cookie = null, $refer = 'https://www.baidu.com')
  257.   {
  258.     $ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255);
  259.     $header[] = "CLIENT-IP:" . $ip;
  260.     $header[] = "X-FORWARDED-FOR:" . $ip;
  261.     $ch = curl_init();
  262.     curl_setopt($ch, CURLOPT_URL, $url); //设置传输的 url
  263.     curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //发送 http 报头
  264.     curl_setopt($ch, CURLOPT_COOKIE, $cookie); //设置Cookie
  265.     curl_setopt($ch, CURLOPT_REFERER,  $refer); //设置Referer
  266.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  267.     curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); // 解码压缩文件
  268.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
  269.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
  270.     curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
  271.     $output = curl_exec($ch);
  272.     curl_close($ch);
  273.     return $output;
  274.   }
  275. }
  276. $_type = isset($_GET['type']) ? $_GET['type'] : '';
  277. $API = new Api;
  278. switch ($_type) {
  279.   case 'baidu':
  280.     $_res = $API->baiduredian();
  281.     break;
  282.   case 'zhihu':
  283.     $_res = $API->zhihuHot();
  284.     break;
  285.   case 'weibo':
  286.     $_res = $API->wbresou();
  287.     break;
  288.   case 'bilihot':
  289.     $_res = $API->bilibili_hot();
  290.     break;
  291.   case 'biliall':
  292.     $_res = $API->bilibili_rankall();
  293.     break;
  294.   case 'douyin':
  295.     $_res = $API->douyin();
  296.     break;
  297.   case 'history':
  298.     $_res = $API->history();
  299.     break;
  300.   case 'csdn':
  301.     $_res = $API->csdn();
  302.     break;
  303.   case 'sspai':
  304.     $_res = $API->sspai();
  305.     break;
  306.   default:
  307.     $_res = ['success' => false, 'message' => '参数不完整'];
  308.     break;
  309. }
  310. $_res['copyright'] = '聚合热搜榜';
  311. exit(json_encode($_res,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));
  312. ?>


本文网址:https://www.zztuku.com/detail-13771.html
站长图库 - 聚合热搜热榜PHP接口API源码
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐