1096 lines
45 KiB
PHP
1096 lines
45 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\common\controller\Api;
|
||
use think\Db;
|
||
use think\Cache;
|
||
use think\Request;
|
||
use QL\QueryList;
|
||
/**
|
||
* @name 热搜接口
|
||
* @author AI Coder
|
||
* @date 2026-04-26
|
||
* @desc 提供热榜数据读取和采集刷新功能
|
||
* @update 新增read方法读取本地缓存数据,新增refresh方法触发采集
|
||
*/
|
||
class Hot extends Api
|
||
{
|
||
protected $noNeedLogin = ['*'];
|
||
protected $noNeedRight = ['*'];
|
||
|
||
private static $hotMap = [
|
||
'baidu' => ['file' => 'baidu.txt', 'name' => '百度'],
|
||
'weibo' => ['file' => 'weibo.txt', 'name' => '微博'],
|
||
'zhihu' => ['file' => 'zhihu.txt', 'name' => '知乎'],
|
||
'douyin' => ['file' => 'douyin.txt', 'name' => '抖音'],
|
||
'bilibili' => ['file' => 'bilibili.txt', 'name' => 'B站'],
|
||
'csdn' => ['file' => 'csdn.txt', 'name' => 'CSDN'],
|
||
'toutiao' => ['file' => 'toutiao.txt', 'name' => '头条'],
|
||
'github' => ['file' => 'github.txt', 'name' => 'GitHub'],
|
||
'sousou' => ['file' => 'sousou.txt', 'name' => '360'],
|
||
'sougou' => ['file' => 'sougou.txt', 'name' => '搜狗'],
|
||
'ke' => ['file' => 'ke.txt', 'name' => '36氪'],
|
||
'juejin' => ['file' => 'juejin.txt', 'name' => '掘金'],
|
||
'xueqiu' => ['file' => 'xueqiu.txt', 'name' => '雪球'],
|
||
'it' => ['file' => 'it.txt', 'name' => 'IT之家'],
|
||
'pengpai' => ['file' => 'pengpai.txt', 'name' => '澎湃'],
|
||
'tengxun' => ['file' => 'tengxun.txt', 'name' => '腾讯'],
|
||
'acfun' => ['file' => 'acfun.txt', 'name' => 'AcFun'],
|
||
'sm' => ['file' => 'sm.txt', 'name' => '神马'],
|
||
'woshipm' => ['file' => 'woshipm.txt', 'name' => '产品经理'],
|
||
'ximalaya' => ['file' => 'ximalaya.txt', 'name' => '喜马拉雅'],
|
||
'shaoshupai'=> ['file' => 'shaoshupai.txt','name' => '少数派'],
|
||
'tieba' => ['file' => 'tieba.txt', 'name' => '贴吧'],
|
||
'hupu' => ['file' => 'hupu.txt', 'name' => '虎扑'],
|
||
'haokan' => ['file' => 'haokan.txt', 'name' => '好看'],
|
||
'kaifazhe' => ['file' => 'kaifazhe.txt', 'name' => '开发者'],
|
||
'zhongguo' => ['file' => 'zhongguo.txt', 'name' => '中国搜索'],
|
||
'huaerjie' => ['file' => 'huaerjie.txt', 'name' => '华尔街'],
|
||
'jifeng' => ['file' => 'jifeng.txt', 'name' => '机锋'],
|
||
'cpu' => ['file' => 'cpu.txt', 'name' => 'CPU'],
|
||
'phone' => ['file' => 'phone.txt', 'name' => '手机'],
|
||
];
|
||
|
||
/**
|
||
* @name 读取热搜数据
|
||
* @desc 从本地txt文件读取已采集的热搜数据,支持单平台和全部平台
|
||
* @param string type 平台类型(baidu/weibo/zhihu等),all为全部
|
||
*/
|
||
public function read()
|
||
{
|
||
$type = input('get.type', 'all', 'trim');
|
||
if ($type === 'all') {
|
||
$result = [];
|
||
foreach (self::$hotMap as $key => $item) {
|
||
$result[$key] = $this->readHotFile($item['file'], $item['name']);
|
||
}
|
||
$this->success('成功', $result);
|
||
} else {
|
||
if (!isset(self::$hotMap[$type])) {
|
||
$this->error('不支持的平台类型: ' . $type);
|
||
}
|
||
$item = self::$hotMap[$type];
|
||
$data = $this->readHotFile($item['file'], $item['name']);
|
||
$this->success('成功', $data);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @name 读取热搜文件
|
||
* @desc 从本地txt文件读取JSON数据
|
||
*/
|
||
private function readHotFile($filename, $name)
|
||
{
|
||
$filepath = './hot/' . $filename;
|
||
if (!file_exists($filepath)) {
|
||
return ['name' => $name, 'data' => [], 'update_time' => null, 'status' => 'no_data'];
|
||
}
|
||
$content = file_get_contents($filepath);
|
||
if (empty($content)) {
|
||
return ['name' => $name, 'data' => [], 'update_time' => null, 'status' => 'empty'];
|
||
}
|
||
$data = json_decode($content, true);
|
||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||
return ['name' => $name, 'data' => [], 'update_time' => null, 'status' => 'parse_error'];
|
||
}
|
||
$mtime = filemtime($filepath);
|
||
return [
|
||
'name' => $name,
|
||
'data' => $data ?: [],
|
||
'update_time'=> $mtime ? date('Y-m-d H:i:s', $mtime) : null,
|
||
'count' => is_array($data) ? count($data) : 0,
|
||
'status' => 'ok',
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @name 刷新热搜数据
|
||
* @desc 触发采集并返回采集结果状态
|
||
*/
|
||
public function refresh()
|
||
{
|
||
$type = input('post.type', 'all', 'trim');
|
||
$results = [];
|
||
if ($type === 'all') {
|
||
$results['baidu'] = $this->BaiDuHot();
|
||
$results['weibo'] = $this->WeiBoHot();
|
||
$results['zhihu'] = $this->ZhiHuHot();
|
||
$results['douyin'] = $this->DouYinHot();
|
||
$results['bilibili'] = $this->BiliBiliHot();
|
||
$results['csdn'] = $this->CsdnHot();
|
||
$results['toutiao'] = $this->TouTiaoHot();
|
||
$results['github'] = $this->GitHubHot();
|
||
} else {
|
||
$methodMap = [
|
||
'baidu' => 'BaiDuHot',
|
||
'weibo' => 'WeiBoHot',
|
||
'zhihu' => 'ZhiHuHot',
|
||
'douyin' => 'DouYinHot',
|
||
'bilibili' => 'BiliBiliHot',
|
||
'csdn' => 'CsdnHot',
|
||
'toutiao' => 'TouTiaoHot',
|
||
'github' => 'GitHubHot',
|
||
'sousou' => 'SouSouHot',
|
||
'sougou' => 'SouGouHot',
|
||
'ke' => 'KeHot',
|
||
'juejin' => 'JueJinHot',
|
||
'xueqiu' => 'XueQiuHot',
|
||
'it' => 'ItHot',
|
||
'pengpai' => 'PengPaiHot',
|
||
'tengxun' => 'TengXunHot',
|
||
'acfun' => 'AcFunHot',
|
||
'sm' => 'SmHot',
|
||
'woshipm' => 'WoshipmHot',
|
||
'ximalaya' => 'XiMaLaYaHot',
|
||
'shaoshupai'=> 'ShaoShuPaiHot',
|
||
'tieba' => 'TieBaHot',
|
||
'hupu' => 'HuPuHot',
|
||
'haokan' => 'HaoKanHot',
|
||
'kaifazhe' => 'KaiFaZheHot',
|
||
'zhongguo' => 'ZhongGuoHot',
|
||
'huaerjie' => 'HuaErJieHot',
|
||
'jifeng' => 'JiFengHot',
|
||
'cpu' => 'CpuHot',
|
||
'phone' => 'PhoneHot',
|
||
];
|
||
if (!isset($methodMap[$type])) {
|
||
$this->error('不支持的平台类型: ' . $type);
|
||
}
|
||
$method = $methodMap[$type];
|
||
$results[$type] = $this->$method();
|
||
}
|
||
$this->success('刷新完成', $results);
|
||
}
|
||
// 百度热搜
|
||
public function BaiDuHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.content_1YWBm .c-single-text-ellipsis', 'text'],
|
||
'num' => ['.trend_2RttY > .hot-index_1Bl1a', 'text'],
|
||
];
|
||
$range = '.container-bg_lQ801 div .category-wrap_iQLoo'; // 列表项的选择器
|
||
$baidu = QueryList::get('https://top.baidu.com/board?tab=realtime')->rules($rules)->range($range)->query()->getData();
|
||
if(empty($baidu->all())){
|
||
return '百度采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($baidu as $k => $v) {
|
||
if (empty($v['num'])) {
|
||
unset($baidu[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => formatNumber($v['num']),
|
||
'url' => "https://www.baidu.com/s?wd=" . $v['title']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/baidu.txt",json_encode($newArray, 320))){
|
||
return '百度写入成功';
|
||
}else{
|
||
return '百度写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 微博热搜
|
||
public function WeiBoHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.td-02 a', 'text'],
|
||
'num' => ['.td-02 span', 'text'],
|
||
];
|
||
$range = 'tbody tr'; // 列表项的选择器
|
||
$weibo = QueryList::get('https://s.weibo.com/top/summary',['cate'=>'realtimehot'],[
|
||
'timeout'=>30,//超时设置
|
||
'headers'=>[
|
||
'User-Agent'=>'Mozilla/5.0(Windows NT 10.0;Win64; x64)AppleWebkit/537.36(KHTML,like Gecko) Chrome/80.0.3987.163 Safari/537.36',
|
||
'Cookie'=>'SCF=AgKIMplmBB1ET4y9rZwakQaxBz416jV5v8fuNy6ykOUTJK4R0sOBlGjjcvm8-8gHQqxFrlup8rY1NSzE2gRlZjg.; ALF=1673774158; SUB=_2AkMUXXdhf8NxqwFRmP4VzWjgaoV3ygvEieKiAYa6JRMxHRl-yT9jqksptRB6P91ZjrTi_SNuVdFbqS3tNoRqm2GDSsWj; SINAGLOBAL=95859429732.16798.1661925014436; UOR=www.baidu.com,weibo.com,www.baidu.com; _s_tentry=www.baidu.com; Apache=832300997165.8624.1665365740677; ULV=1665365740702:6:1:1:832300997165.8624.1665365740677:1664181779010'
|
||
]
|
||
])->rules($rules)->range($range)->query()->getData();
|
||
if(empty($weibo->all())){
|
||
return '微博采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($weibo as $k => $v) {
|
||
if (empty($v['num'])) {
|
||
unset($weibo[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => formatNumber((int)str_replace(["剧集 ","综艺 ",'盛典 ','音乐 ','电影 ','演出 '], "", $v['num'])),
|
||
'url' => 'https://s.weibo.com/weibo?q='.$v['title']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/weibo.txt",json_encode($newArray, 320))){
|
||
return '微博写入成功';
|
||
}else{
|
||
return '微博写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 知乎热榜
|
||
public function ZhiHuHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.HotList-itemTitle', 'text'],
|
||
'num' => ['.HotList-itemMetrics', 'text'],
|
||
];
|
||
$range = '.Card > .HotList-item'; // 列表项的选择器
|
||
$zhihu = QueryList::get('https://www.zhihu.com/billboard')->rules($rules)->range($range)->query()->getData();
|
||
if(empty($zhihu->all())){
|
||
return '知乎采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($zhihu as $k => $v) {
|
||
if(empty($v['num'])){
|
||
unset($zhihu[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => str_replace(['热度',' '], "", $v['num']),
|
||
'url' => 'https://www.zhihu.com/search?type=content&q='.$v['title']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/zhihu.txt",json_encode($newArray, 320))){
|
||
return '知乎写入成功';
|
||
}else{
|
||
return '知乎写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 抖音热榜
|
||
public function DouYinHot()
|
||
{
|
||
$result = callApi('https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/word/?reflow_source=reflow_page&msToken=4WdH4UNufiy_V_T9qfE47fkvctrZzmana-6_KdEAq3rgN0-cVJZ3b9g9E5x08xct9K3NdqcPDvVcFwFSQQ645wTjkEhdB5-oPEoKveLhB0fjtHGo6S24OtLAXgEZ9g%3D%3D&a_bogus=x7-Ekc2%2FMsm19jfFfXkz9Hvm5YE0YW5wgZEzHZxU7zwo');
|
||
if($result !== false){
|
||
$douyin = isset(json_decode($result, true)['word_list'])?json_decode($result, true)['word_list']:'';
|
||
if ($douyin) {
|
||
$newArray = [];
|
||
foreach ($douyin as $item) {
|
||
$newItem = [
|
||
'title' => $item['word'],
|
||
'num' => formatNumber($item['hot_value']),
|
||
'url' => 'https://www.douyin.com/search/'.$item['word']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/douyin.txt",json_encode($newArray, 320))){
|
||
return '抖音写入成功';
|
||
}else{
|
||
return '抖音写入失败';
|
||
}
|
||
} else {
|
||
return '抖音采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 360热搜榜
|
||
public function SouSouHot()
|
||
{
|
||
$result = callApi('https://ranks.hao.360.com/mbsug-api/hotnewsquery?type=news&realhot_limit=50&src=hao_ranklist_so');
|
||
if($result !== false){
|
||
$sousou = json_decode($result, true);
|
||
if ($sousou) {
|
||
$newArray = [];
|
||
foreach ($sousou as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => formatNumber($item['score']),
|
||
'url' => $item['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/sousou.txt",json_encode($newArray, 320))){
|
||
return '360写入成功';
|
||
}else{
|
||
return '360写入失败';
|
||
}
|
||
} else {
|
||
return '360采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 搜狗热搜榜
|
||
public function SouGouHot()
|
||
{
|
||
$result = callApi('https://go.ie.sogou.com/hot_ranks');
|
||
if($result !== false){
|
||
$sougou = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($sougou) {
|
||
$newArray = [];
|
||
foreach ($sougou as $item) {
|
||
$newItem = [
|
||
'title' => $item['attributes']['title'],
|
||
'num' => formatNumber($item['attributes']['num']),
|
||
'url' => 'https://www.sogou.com/sie?query='.$item['attributes']['title']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/sougou.txt",json_encode($newArray, 320))){
|
||
return '搜狗写入成功';
|
||
}else{
|
||
return '搜狗写入失败';
|
||
}
|
||
} else {
|
||
return '搜狗采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 今日头条热榜
|
||
public function TouTiaoHot()
|
||
{
|
||
$result = callApi('https://www.toutiao.com/hot-event/hot-board/?origin=toutiao_pc');
|
||
if($result !== false){
|
||
$toutiao = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($toutiao) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($toutiao as $item) {
|
||
$newItem = [
|
||
"title" => $item["Title"],
|
||
"num" => formatNumber($item["HotValue"]),
|
||
'url' => $item['Url']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/toutiao.txt",json_encode($newArray, 320))){
|
||
return '今日头条写入成功';
|
||
}else{
|
||
return '今日头条写入失败';
|
||
}
|
||
} else {
|
||
return '今日头条采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 哔哩哔哩排行榜
|
||
public function BiliBiliHot()
|
||
{
|
||
$result = callApi('https://api.bilibili.com/x/web-interface/ranking/v2?rid=0&type=all');
|
||
if($result !== false){
|
||
$bilibili = isset(json_decode($result, true)['data']['list'])?json_decode($result, true)['data']['list']:'';
|
||
if ($bilibili) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($bilibili as $item) {
|
||
$newItem = [
|
||
"title" => $item["title"],
|
||
"num" => formatNumber($item["stat"]['view']),
|
||
'url' => $item["short_link_v2"]
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/bilibili.txt",json_encode($newArray, 320))){
|
||
return '哔哩哔哩写入成功';
|
||
}else{
|
||
return '哔哩哔哩写入失败';
|
||
}
|
||
} else {
|
||
return "哔哩哔哩采集失败";
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// CSDN综合热搜榜
|
||
public function CsdnHot()
|
||
{
|
||
$result = callApi('https://bang.blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=50');
|
||
if($result !== false){
|
||
$csdn = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($csdn) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($csdn as $item) {
|
||
$newItem = [
|
||
"title" => $item["articleTitle"],
|
||
"num" => formatNumber($item["hotRankScore"]),
|
||
'url' => $item['articleDetailUrl']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/csdn.txt",json_encode($newArray, 320))){
|
||
return 'CSDN写入成功';
|
||
}else{
|
||
return 'CSDN写入失败';
|
||
}
|
||
} else {
|
||
return 'CSDN采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 36氪推荐榜
|
||
public function KeHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.title-wrapper > .article-item-title', 'text'],
|
||
'num' => ['.HotList-itemMetrics', 'text'],
|
||
'url' => ['.title-wrapper > a','href']
|
||
];
|
||
$range = '.information-flow-list > .information-flow-item'; // 列表项的选择器
|
||
$ke = QueryList::get('https://36kr.com/information/web_recommend/')->rules($rules)->range($range)->query()->getData();
|
||
if(empty($ke->all())){
|
||
return '36氪采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($ke as $k => $v) {
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => $v['num'],
|
||
'url' => 'https://36kr.com'.$v['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/ke.txt",json_encode($newArray, 320))){
|
||
return '36氪写入成功';
|
||
}else{
|
||
return '36氪写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 稀土掘金文章热榜
|
||
public function JueJinHot()
|
||
{
|
||
$result = callApi('https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot&aid=2608&uuid=7216360499583157771&spider=0');
|
||
if($result !== false){
|
||
$juejin = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($juejin) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($juejin as $item) {
|
||
$newItem = [
|
||
"title" => $item["content"]["title"],
|
||
"num" => formatNumber((int)str_replace(' 热度', "", $item["content_counter"]["hot_rank"])),
|
||
'url' => 'https://juejin.cn/post/'.$item['content']['content_id']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/juejin.txt",json_encode($newArray, 320))){
|
||
return '稀土掘金写入成功';
|
||
}else{
|
||
return '稀土掘金写入失败';
|
||
}
|
||
} else {
|
||
return '稀土掘金采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 雪球
|
||
public function XueQiuHot()
|
||
{
|
||
$result = callApi('https://xueqiu.com/query/v1/status/hots.json?count=15&page=1&scope=day&type=news','acw_tc=2760826317012516550748033e6c31e7801026f8a996a32a780e5b0c193c16; xq_a_token=4fda997cf0d3bc4ef43eba42532cf38a54bcbc00; xqat=4fda997cf0d3bc4ef43eba42532cf38a54bcbc00; xq_r_token=a440894245f0f9be071ea5c41d674edb42789120; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTcwMzI5MTg4MiwiY3RtIjoxNzAxMjUxNjM5MTU4LCJjaWQiOiJkOWQwbjRBWnVwIn0.hU5vvXg1IyYWQeFoAwDu0oNXD0kEMxgvpEw0clZ8JpN6ysy6q0EmYMq-9v38y6NWqnfTocmP_OBYQxH3YLSJ0C-LFQbUKYVjEqVMUJifH0nnqXyTqplIgJkliaXvqQ2vWPWH-XchS3iRBE0DWVbFJH1WL8kM_YEyZMn_DE3c6Isoxb2jj1UMWRq7BlNA7Wa8bckApuDZ7eh07dkcbvNG6jzqyqS0c1sb56rqBtoqC3TqeMjDRrUBgrexrZIaSpHWr6Y4BI3dU60VgyyIZ6BAEj0o9Y_VLUpwsZB3MfZKhMsmYh8iITipsvq_VKntkm1X7gX-eAUnWT4SxWxXi4XLJw; cookiesu=951701251655081; u=951701251655081; device_id=ac46d78b7b264f1c095bc547562dc3a3; Hm_lvt_1db88642e346389874251b5a1eded6e3=1701251656; acw_sc__v2=65670bfaf426c75eb17e5f9537a22ab90f284ec0; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1701252623','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36');
|
||
if($result !== false){
|
||
$xueqiu = isset(json_decode($result,true)['data'])?json_decode($result,true)['data']:'';
|
||
if (!empty($xueqiu)) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($xueqiu as $item) {
|
||
$newItem = [
|
||
"title" => $item["title"],
|
||
"num" => formatNumber($item['view_count']),
|
||
'url' => 'https://xueqiu.com'.$item['target']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/xueqiu.txt",json_encode($newArray, 320))){
|
||
return '雪球写入成功';
|
||
}else{
|
||
return '雪球写入失败';
|
||
}
|
||
} else {
|
||
return '雪球采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// IT之家热榜
|
||
public function ItHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['a', 'text'],
|
||
'num' => ['.HotList-itemMetrics', 'text'],
|
||
'url' => ['a','href']
|
||
];
|
||
$range = 'ul > li'; // 列表项的选择器
|
||
$it = QueryList::get('https://www.ithome.com/block/rank.html')->rules($rules)->range($range)->query()->getData();
|
||
if(empty($it->all())){
|
||
return 'it之家采集失败';
|
||
}else{
|
||
foreach ($it as $k => &$v) {
|
||
if(empty($v['title'])){
|
||
unset($it[$k]);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/it.txt",json_encode($it, 320))){
|
||
return 'IT之家写入成功';
|
||
}else{
|
||
return 'IT之家写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 澎湃热榜
|
||
public function PengPaiHot()
|
||
{
|
||
$result = callApi('https://cache.thepaper.cn/contentapi/wwwIndex/rightSidebar');
|
||
if($result !== false){
|
||
$pengpai = isset(json_decode($result,true)['data']['hotNews'])?json_decode($result,true)['data']['hotNews']:'';
|
||
if ($pengpai) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($pengpai as $item) {
|
||
$newItem = [
|
||
"title" => $item["name"],
|
||
"num" => $item['praiseTimes'].'点赞',
|
||
'url' => 'https://www.thepaper.cn/newsDetail_forward_'.$item['contId']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/pengpai.txt",json_encode($newArray, 320))){
|
||
return '澎湃写入成功';
|
||
}else{
|
||
return '澎湃写入失败';
|
||
}
|
||
} else {
|
||
return $this->e;
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 腾讯热点榜
|
||
public function TengXunHot()
|
||
{
|
||
$result = callApi('https://r.inews.qq.com/gw/event/pc_hot_ranking_list?ids_hash=&offset=0&page_size=50&appver=15.5_qqnews_7.1.60');
|
||
if($result !== false){
|
||
$tengxun = isset(json_decode($result,true)['idlist'][0]['newslist'])?json_decode($result,true)['idlist'][0]['newslist']:'';
|
||
if ($tengxun) {
|
||
unset($tengxun[0]);
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($tengxun as $item) {
|
||
$newItem = [
|
||
"title" => $item["title"],
|
||
"num" => formatNumber($item['hotEvent']['hotScore']),
|
||
'url' => $item['url']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/tengxun.txt",json_encode($newArray, 320))){
|
||
return '腾讯写入成功';
|
||
}else{
|
||
return '腾讯写入失败';
|
||
}
|
||
} else {
|
||
return "腾讯采集失败";
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// AcFun排行榜
|
||
public function AcFunHot()
|
||
{
|
||
$result = callApi('https://www.acfun.cn/rest/pc-direct/rank/channel?channelId=&subChannelId=&rankLimit=50&rankPeriod=DAY');
|
||
if($result !== false){
|
||
$acfun = isset(json_decode($result,true)['rankList'])?json_decode($result,true)['rankList']:'';
|
||
if ($acfun) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($acfun as $item) {
|
||
$newItem = [
|
||
"title" => $item["title"],
|
||
"num" => $item['viewCountShow'],
|
||
'url' => 'https://www.acfun.cn/v/ac'.$item['contentId']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/acfun.txt",json_encode($newArray, 320))){
|
||
return 'AuFun写入成功';
|
||
}else{
|
||
return 'AuFun写入失败';
|
||
}
|
||
} else {
|
||
return 'AuFun采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 神马热搜榜
|
||
public function SmHot()
|
||
{
|
||
$result = callApi('https://biz.quark.cn/api/trending/ranking/getNewsRanking?modules=hotNews&__t=1701279475304&ver=1&chid=1701279475304&uc_param_str=dnfrpfbivessbtbmnilauputogpintnwmtsvcppcprsnnnchmicckpgixsnx&from=hot_page');
|
||
if($result !== false){
|
||
$sm = isset(json_decode($result,true)['data']['hotNews']['item'])?json_decode($result,true)['data']['hotNews']['item']:'';
|
||
if ($sm) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($sm as $item) {
|
||
$newItem = [
|
||
"title" => $item["title"],
|
||
"num" => formatNumber($item['hot']),
|
||
'url' => $item['url']
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/sm.txt",json_encode($newArray, 320))){
|
||
return '神马写入成功';
|
||
}else{
|
||
return '神马写入失败';
|
||
}
|
||
} else {
|
||
return '神马采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 人人都是产品经理热门榜
|
||
public function WoshipmHot()
|
||
{
|
||
$result = callApi('https://www.woshipm.com/api2/app/article/popular/daily');
|
||
if($result !== false){
|
||
$woshipm = isset(json_decode($result,true)['RESULT'])?json_decode($result,true)['RESULT']:'';
|
||
if ($woshipm) {
|
||
$newArray = []; // 创建一个新数组
|
||
// 遍历原始数组,提取需要的元素
|
||
foreach ($woshipm as $item) {
|
||
$newItem = [
|
||
"title" => $item['data']["articleTitle"],
|
||
"num" => $item['scores'],
|
||
'url' => 'https://www.woshipm.com/operate/'.$item['data']['id'].'.html'
|
||
];
|
||
array_push($newArray, $newItem); // 将新元素加入新数组
|
||
}
|
||
if(writeToTxt("./hot/woshipm.txt",json_encode($newArray, 320))){
|
||
return '产品经理写入成功';
|
||
}else{
|
||
return '产品经理写入失败';
|
||
}
|
||
} else {
|
||
return '产品经理采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
|
||
}
|
||
// 喜马拉雅热播榜
|
||
public function XiMaLaYaHot()
|
||
{
|
||
$result = callApi('https://www.ximalaya.com/revision/rank/v4/element?rankingId=100006');
|
||
if($result !== false){
|
||
$ximalaya = isset(json_decode($result, true)['data']['rankList'][0]['albums'])?json_decode($result, true)['data']['rankList'][0]['albums']:'';
|
||
if ($ximalaya) {
|
||
$newArray = [];
|
||
foreach ($ximalaya as $item) {
|
||
$newItem = [
|
||
'title' => $item['albumTitle'],
|
||
'num' => formatNumber($item['playCount']),
|
||
'url' => 'https://www.ximalaya.com'.$item['albumUrl']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/ximalaya.txt",json_encode($newArray, 320))){
|
||
return '喜马拉雅写入成功';
|
||
}else{
|
||
return '喜马拉雅写入失败';
|
||
}
|
||
} else {
|
||
return '喜马拉雅采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 少数派热门榜
|
||
public function ShaoShuPaiHot()
|
||
{
|
||
$result = callApi('https://sspai.com/api/v1/article/tag/page/get?limit=30&offset=0&created_at=1701316828&tag=热门文章&released=false');
|
||
if($result !== false){
|
||
$shaoshupai = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($shaoshupai) {
|
||
$newArray = [];
|
||
foreach ($shaoshupai as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => $item['like_count'].'喜欢',
|
||
'url' => 'https://sspai.com/post/'.$item['id']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/shaoshupai.txt",json_encode($newArray, 320))){
|
||
return '少数派写入成功';
|
||
}else{
|
||
return '少数派写入失败';
|
||
}
|
||
} else {
|
||
return '少数派采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 百度贴吧
|
||
public function TieBaHot()
|
||
{
|
||
$result = callApi('https://tieba.baidu.com/hottopic/browse/topicList');
|
||
if($result !== false){
|
||
$tieba = isset(json_decode($result, true)['data']['bang_topic']['topic_list'])?json_decode($result, true)['data']['bang_topic']['topic_list']:'';
|
||
if ($tieba) {
|
||
$newArray = [];
|
||
foreach ($tieba as $item) {
|
||
$newItem = [
|
||
'title' => $item['topic_name'],
|
||
'num' => formatNumber($item['discuss_num']),
|
||
'url' => $item['topic_url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/tieba.txt",json_encode($newArray, 320))){
|
||
return '贴吧写入成功';
|
||
}else{
|
||
return '贴吧写入失败';
|
||
}
|
||
} else {
|
||
return '贴吧采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 虎扑
|
||
public function HuPuHot()
|
||
{
|
||
$result = callApi('https://www.hupu.com/home/v1/hot');
|
||
if($result !== false){
|
||
$hupu = isset(json_decode($result, true)['data'][2]['hotList'])?json_decode($result, true)['data'][2]['hotList']:'';
|
||
if ($hupu) {
|
||
$newArray = [];
|
||
foreach ($hupu as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => "",
|
||
'url' => "https://bbs.hupu.com/".$item['tid'].'.html'
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/hupu.txt",json_encode($newArray, 320))){
|
||
return '虎扑写入成功';
|
||
}else{
|
||
return '虎扑写入失败';
|
||
}
|
||
} else {
|
||
return '虎扑采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 好看热榜
|
||
public function HaoKanHot()
|
||
{
|
||
$result = callApi('https://haokan.baidu.com/videoui/page/pc/toplist?type=hotvideo&sfrom=haokan_web_banner&pageSize=50&_format=json');
|
||
if($result !== false){
|
||
$haokan = isset(json_decode($result, true)['apiData']['response']['video'])?json_decode($result, true)['apiData']['response']['video']:'';
|
||
if ($haokan) {
|
||
$newArray = [];
|
||
foreach ($haokan as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => formatNumber($item['hot']),
|
||
'url' => $item['pageUrl']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/haokan.txt",json_encode($newArray, 320))){
|
||
return '好看写入成功';
|
||
}else{
|
||
return '好看写入失败';
|
||
}
|
||
} else {
|
||
return '好看采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 开发者搜索
|
||
public function KaiFaZheHot()
|
||
{
|
||
$result = callApi('https://kaifa.baidu.com/rest/v1/news/hot?pageNum=1&pageSize=50');
|
||
if($result !== false){
|
||
$kaifazhe = isset(json_decode($result, true)['data']['data'])?json_decode($result, true)['data']['data']:'';
|
||
if ($kaifazhe) {
|
||
$newArray = [];
|
||
foreach ($kaifazhe as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => '',
|
||
'url' => $item['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/kaifazhe.txt",json_encode($newArray, 320))){
|
||
return '开发者写入成功';
|
||
}else{
|
||
return '开发者写入失败';
|
||
}
|
||
} else {
|
||
return '开发者采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// GitHub仓库热榜
|
||
public function GitHubHot()
|
||
{
|
||
$result = callApi('https://kaifa.baidu.com/rest/v1/home/github?optionLanguage=&optionSince=');
|
||
if($result !== false){
|
||
$github = isset(json_decode($result, true)['data']['trendingList'])?json_decode($result, true)['data']['trendingList']:'';
|
||
if ($github) {
|
||
$newArray = [];
|
||
foreach ($github as $item) {
|
||
$newItem = [
|
||
'title' => $item['title'],
|
||
'num' => formatNumber($item['fork']),
|
||
'url' => $item['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/github.txt",json_encode($newArray, 320))){
|
||
return 'Github写入成功';
|
||
}else{
|
||
return 'Github写入失败';
|
||
}
|
||
} else {
|
||
return 'GitHub采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 中国搜索
|
||
public function ZhongGuoHot()
|
||
{
|
||
$result = callApi('http://www.chinaso.com/v5/general/v1/search/hotnews?num=50&hntid=1');
|
||
if($result !== false){
|
||
$zhongguo = isset(json_decode($result, true)['data'])?json_decode($result, true)['data']:'';
|
||
if ($zhongguo) {
|
||
$newArray = [];
|
||
foreach ($zhongguo as $item) {
|
||
$newItem = [
|
||
'title' => $item['event_query'],
|
||
'num' => $item['hot_value'],
|
||
'url' => 'http://www.chinaso.com/newssearch/all/allResults?q='.$item['event_query']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/zhongguo.txt",json_encode($newArray, 320))){
|
||
return '中国搜索写入成功';
|
||
}else{
|
||
return '中国搜索写入失败';
|
||
}
|
||
} else {
|
||
return '中国搜索采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 华尔街见闻最新资讯
|
||
public function HuaErJieHot()
|
||
{
|
||
$result = callApi('https://api-one-wscn.awtmt.com/apiv1/content/information-flow?channel=global&accept=article&cursor=&limit=30&action=upglide');
|
||
if($result !== false){
|
||
$huaerjie = isset(json_decode($result, true)['data']['items'])?json_decode($result, true)['data']['items']:'';
|
||
if ($huaerjie) {
|
||
$newArray = [];
|
||
foreach ($huaerjie as $item) {
|
||
$newItem = [
|
||
'title' => $item['resource']['title'],
|
||
'num' => '',
|
||
'url' => $item['resource']['uri']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
if(writeToTxt("./hot/huaerjie.txt",json_encode($newArray, 320))){
|
||
return '华尔街见闻写入成功';
|
||
}else{
|
||
return '华尔街见闻写入失败';
|
||
}
|
||
} else {
|
||
return '华尔街见闻采集失败';
|
||
}
|
||
}else{
|
||
return '错误!';
|
||
}
|
||
}
|
||
// 机锋网
|
||
public function JiFengHot()
|
||
{
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['p', 'text'],
|
||
'url' => ['','href']
|
||
];
|
||
$range = '.left-box a'; // 列表项的选择器
|
||
$jifeng = QueryList::get('https://www.gfan.com')->rules($rules)->range($range)->query()->getData();
|
||
if(empty($jifeng->all())){
|
||
return '机锋采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($jifeng as $k => $v) {
|
||
if (empty($v['title'])) {
|
||
unset($jifeng[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => '',
|
||
'url' => $v['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/jifeng.txt",json_encode($newArray, 320))){
|
||
return '机锋写入成功';
|
||
}else{
|
||
return '机锋写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 中关村
|
||
public function CpuHot()
|
||
{
|
||
$url = 'https://top.zol.com.cn/compositor/28/cpu.html';
|
||
//手动转码
|
||
$html = iconv('GBK','UTF-8',file_get_contents($url));
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.rank__name > a', 'text'],
|
||
'num' => ['.rank__price', 'text'],
|
||
'url' => ['.rank__name > a','href']
|
||
];
|
||
$range = '.rank-list .rank-list__item'; // 列表项的选择器
|
||
$cpu = QueryList::html($html)->rules($rules)->range($range)->query()->getData();
|
||
if(empty($cpu->all())){
|
||
return 'cpu采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($cpu as $k => $v) {
|
||
if (empty($v['title'])) {
|
||
unset($cpu[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => $v['num'],
|
||
'url' => $v['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/cpu.txt",json_encode($newArray, 320))){
|
||
return 'cpu写入成功';
|
||
}else{
|
||
return 'cpu写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 中关村手机
|
||
public function PhoneHot()
|
||
{
|
||
$url = 'https://top.zol.com.cn/compositor/57/cell_phone.html';
|
||
//手动转码
|
||
$html = iconv('GBK','UTF-8',file_get_contents($url));
|
||
// 采集当前页的列表数据
|
||
$rules = [
|
||
'title' => ['.rank__name > a', 'text'],
|
||
'num' => ['.rank__price', 'text'],
|
||
'url' => ['.rank__name > a','href']
|
||
];
|
||
$range = '.rank-list .rank-list__item'; // 列表项的选择器
|
||
$phone = QueryList::html($html)->rules($rules)->range($range)->query()->getData();
|
||
if(empty($phone->all())){
|
||
return '手机采集失败';
|
||
}else{
|
||
$newArray = [];
|
||
foreach ($phone as $k => $v) {
|
||
if (empty($v['title'])) {
|
||
unset($phone[$k]);
|
||
}else{
|
||
$newItem = [
|
||
'title' => $v['title'],
|
||
'num' => $v['num'],
|
||
'url' => $v['url']
|
||
];
|
||
array_push($newArray,$newItem);
|
||
}
|
||
}
|
||
if(writeToTxt("./hot/phone.txt",json_encode($newArray, 320))){
|
||
return '手机写入成功';
|
||
}else{
|
||
return '手机写入失败';
|
||
}
|
||
}
|
||
}
|
||
// 定时综合调用
|
||
public function synthesize()
|
||
{
|
||
$data['baidu'] = $this->BaiDuHot();//百度
|
||
$data['shenma'] = $this->SmHot();//神马
|
||
$data['weibo'] = $this->WeiBoHot();//微博
|
||
$data['zhihu'] = $this->ZhiHuHot();//知乎
|
||
$data['douyin'] = $this->DouYinHot();//抖音
|
||
$data['sousou'] = $this->SouSouHot();//360
|
||
$data['sougou'] = $this->SouGouHot();//搜狗
|
||
$data['toutiao'] = $this->TouTiaoHot();//今日头条
|
||
$data['bilibili'] = $this->BiliBiliHot();//哔哩哔哩
|
||
$data['csdn'] = $this->CsdnHot();//CSDN博客
|
||
$data['ke'] = $this->KeHot();//36氪
|
||
$data['juejin'] = $this->JueJinHot();//稀土掘金
|
||
$data['xueqiu'] = $this->XueQiuHot();//雪球
|
||
$data['it'] = $this->ItHot();//IT之家
|
||
$data['pengpai'] = $this->PengPaiHot();//澎湃新闻
|
||
$data['tengxun'] = $this->TengXunHot();//腾讯
|
||
$data['aufun'] = $this->AcFunHot();//AcFun
|
||
$data['chanpin'] = $this->WoshipmHot();//人人都是产品经理
|
||
$data['ximalaya'] = $this->XiMaLaYaHot();//喜马拉雅
|
||
$data['shaoshupai'] = $this->ShaoShuPaiHot();//少数派
|
||
$data['tieba'] = $this->TieBaHot();//贴吧
|
||
$data['hupu'] = $this->HuPuHot();//虎扑
|
||
$data['haokan'] = $this->HaoKanHot();//好看
|
||
$data['kaifazhe'] = $this->KaiFaZheHot();//开发者搜索
|
||
$data['github'] = $this->GitHubHot();//GitHub仓库
|
||
$data['zhongguo'] = $this->ZhongGuoHot();//中国搜索
|
||
$data['huaerjie'] = $this->HuaErJieHot();//华尔街见闻
|
||
$data['jifeng'] = $this->JiFengHot();//机锋网
|
||
$data['cpu'] = $this->CpuHot();//CPU
|
||
$data['phone'] = $this->PhoneHot();//手机
|
||
$this->success('更新成功',$data);
|
||
}
|
||
} |