聚合热搜热榜PHP接口源码

本源码接口均抓取采集各大官网数据。

GET请求输入参数输入type=zhihu

参数内容:

zhihu 知乎热榜

weibo 微博热搜

baidu 百度热点

history 历史上的今天

bilihot 哔哩哔哩热搜

biliall 哔哩哔哩日榜

sspai 少数派头条

douyin 抖音热搜

接口源码

<?php

/**
 * 点个关注吧!
 * 接口内容会及时更新维护
 * 有失效可以在评论区说一下
 */
class Api
{

    // 抖音 热搜榜
    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_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 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 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
        ];
    }

    // 百度热点 指数
    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' => '指数',
            'update_time' => date('Y-m-d h:i:s', time()),
            'data' => $tempArr
        ];
    }

    //百度百科  历史上的今天
    public function history()
    {
        $month = date('m', time());
        $day = date('d', time());
        //当前年月日
        $today = date('Y年m月d日');
        //获取接口数据
        $jsonRes = json_decode($this->Curl('https://baike.baidu.com/cms/home/eventsOnHistory/' . $month . '.json', null, null, "https://baike.baidu.com"), true);
        $tempArr = [];
        //统计当日总数
        $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 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' => '少数派',
            'subtitle' => '热榜',
            '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); //设置传输的 url
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //发送 http 报头
        curl_setopt($ch, CURLOPT_COOKIE, $cookie); //设置Cookie
        curl_setopt($ch, CURLOPT_REFERER, $refer); //设置Referer
        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); // 从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}
//$_GET['type'] = 'csdn';
$_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 'sspai':
        $_res = $API->sspai();
        break;
    default:
        $_res = ['success' => false, 'message' => '参数不完整'];
        break;
}
$_res['copyright'] = '聚合热搜榜';
exit(json_encode($_res, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));

  • 19
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
2023聚合索V码是一个具有高度自定义和可扩展性的开索引擎码。该码提供了丰富的功能和灵活的配置选项,使得用户可以根据自己的需求来定制和优化索引擎的行为。 2023聚合索V码的核心部分是索算法和索引建立模块。索算法采用了先进的文本相似度计算和排序算法,可以高效地检索和排序索结果。索引建立模块负责将文档数据进行索引,使得索过程可以更快速地进行。 此外,码还提供了对多种数据的支持,可以从不同的数据中获取数据,并将其整合到索引擎的索引中。用户可以根据自己的需求添加和配置各种数据,以满足不同的索需求。 除了基本的索功能,2023聚合索V码还提供了许多其他功能,如推荐算法、过滤器、自动补全和索历史等。这些功能可以进一步提升用户索体验,并满足用户对于个性化索的需求。 对于开发者来说,2023聚合索V码提供了完善的文档和示例代码,方便开发者学习和使用。开发者可以根据自己的需要对码进行修改和扩展,以满足特定的索需求。 总体来说,2023聚合索V码是一个功能丰富、灵活可定制的索引擎码。通过其提供的灵活配置、多种数据支持和丰富功能,用户可以构建出一个高性能、个性化的索引擎,以满足不同的索需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极简网络科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值