mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-07 21:47:57 +08:00
feat: Add wechat mp homepage (#4696)
This commit is contained in:
11
assets/radar-rules.js
Normal file → Executable file
11
assets/radar-rules.js
Normal file → Executable file
@@ -1748,4 +1748,15 @@
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
'qq.com': {
|
||||||
|
_name: '微信',
|
||||||
|
'mp.weixin': [
|
||||||
|
{
|
||||||
|
title: '公众号栏目',
|
||||||
|
docs: 'https://docs.rsshub.app/new-media.html#gong-zhong-hao-lan-mu-fei-tui-song-li-shi-xiao-xi',
|
||||||
|
source: '/mp/homepage',
|
||||||
|
target: (params, url) => `/wechat/mp/homepage/${new URL(url).searchParams.get('__biz')}/${new URL(url).searchParams.get('hid')}/${new URL(url).searchParams.get('cid') ? new URL(url).searchParams.get('cid') : ''}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
10
docs/new-media.md
Normal file → Executable file
10
docs/new-media.md
Normal file → Executable file
@@ -990,6 +990,16 @@ Supported sub-sites:
|
|||||||
|
|
||||||
<Route author="sanmmm" example="/wechat/ershicimi/59" path="/wechat/ershicimi/:id" :paramsDesc="['公众号id, 打开公众号页, 在 URL 中找到 id']"/>
|
<Route author="sanmmm" example="/wechat/ershicimi/59" path="/wechat/ershicimi/:id" :paramsDesc="['公众号id, 打开公众号页, 在 URL 中找到 id']"/>
|
||||||
|
|
||||||
|
### 公众号栏目 (非推送 & 历史消息)
|
||||||
|
|
||||||
|
<Route author="MisteryMonster" example="/wechat/mp/homepage/MzA3MDM3NjE5NQ==/16" path="/wechat/mp/homepage/:biz/:hid/:cid?" :paramsDesc="['公众号id', '分页id', '页内栏目']" radar="1" anticrawler="1">
|
||||||
|
|
||||||
|
只适用拥有首页模板 (分享链接带有 homepage) 的公众号。例如从公众号分享出来的链接为 <https://mp.weixin.qq.com/mp/homepage?__biz=MzA3MDM3NjE5NQ==&hid=4>,`biz` 为 `MzA3MDM3NjE5NQ==`,`hid` 为 `4`。
|
||||||
|
|
||||||
|
有些页面里会有分栏, `cid` 可以通过元素选择器选中栏目查看`data-index`。如[链接](https://mp.weixin.qq.com/mp/homepage?__biz=MzA3MDM3NjE5NQ==&hid=4)里的 `京都职人` 栏目的 `cid` 为 `0`,`文艺时光` 栏目的 `cid` 为 `2`。如果不清楚的话最左边的栏目为`0`,其右方栏目依次递增 `1`。
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
### 公众平台系统公告栏目
|
### 公众平台系统公告栏目
|
||||||
|
|
||||||
<Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" />
|
<Route author="xyqfer" example="/wechat/announce" path="/wechat/announce" />
|
||||||
|
|||||||
@@ -479,6 +479,7 @@ router.get('/wechat/miniprogram/plugins', require('./routes/tencent/wechat/minip
|
|||||||
router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel'));
|
router.get('/wechat/tgchannel/:id', require('./routes/tencent/wechat/tgchannel'));
|
||||||
router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread'));
|
router.get('/wechat/uread/:userid', require('./routes/tencent/wechat/uread'));
|
||||||
router.get('/wechat/ershicimi/:id', require('./routes/tencent/wechat/ershcimi'));
|
router.get('/wechat/ershicimi/:id', require('./routes/tencent/wechat/ershcimi'));
|
||||||
|
router.get('/wechat/mp/homepage/:biz/:hid/:cid?', require('./routes/tencent/wechat/mp'));
|
||||||
|
|
||||||
// All the Flight Deals
|
// All the Flight Deals
|
||||||
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));
|
router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index'));
|
||||||
|
|||||||
70
lib/routes/tencent/wechat/mp.js
Executable file
70
lib/routes/tencent/wechat/mp.js
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const { biz, hid, cid } = ctx.params;
|
||||||
|
let cidurl = '';
|
||||||
|
if (cid) {
|
||||||
|
cidurl = `&cid=${cid}`;
|
||||||
|
}
|
||||||
|
let hidurl = '';
|
||||||
|
if (hid) {
|
||||||
|
hidurl = `&hid=${hid}`;
|
||||||
|
}
|
||||||
|
const JSONresponse = await got({
|
||||||
|
method: 'post',
|
||||||
|
url: `https://mp.weixin.qq.com/mp/homepage?__biz=${biz}${hidurl}${cidurl}&begin=0&count=5&action=appmsg_list`,
|
||||||
|
});
|
||||||
|
// 主页Html,获取 RSS 标题用
|
||||||
|
const HTMLresponse = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://mp.weixin.qq.com/mp/homepage?__biz=${biz}${hidurl}${cidurl}`,
|
||||||
|
});
|
||||||
|
const list = JSONresponse.data.appmsg_list;
|
||||||
|
const $ = cheerio.load(HTMLresponse.data);
|
||||||
|
// 标题,另外差一个菜单标题!求助
|
||||||
|
const mptitle = $('div.articles_header').find('a').text() + `|` + $('div.articles_header > h2.rich_media_title').text();
|
||||||
|
const articledata = await Promise.all(
|
||||||
|
list.map(async (item) => {
|
||||||
|
const link = item.link.replace('http://', 'https://');
|
||||||
|
const cache = await ctx.cache.get(link);
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(JSON.parse(cache));
|
||||||
|
}
|
||||||
|
const response2 = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: link,
|
||||||
|
});
|
||||||
|
const articleHtml = response2.data;
|
||||||
|
const $2 = cheerio.load(articleHtml);
|
||||||
|
$2('img').removeAttr('src');
|
||||||
|
$2('div#js_profile_qrcode').remove();
|
||||||
|
|
||||||
|
const content = $2('div#js_content.rich_media_content')
|
||||||
|
.html()
|
||||||
|
.replace('iframe/preview.html?width=500&height=375&', 'txp/iframe/player.html?')
|
||||||
|
.replace('<iframe ', '<iframe width="640" height="360"')
|
||||||
|
.replace(/data-src/g, 'src');
|
||||||
|
const author = $2('div#meta_content:not(:last-child)').text();
|
||||||
|
const single = {
|
||||||
|
content,
|
||||||
|
author,
|
||||||
|
};
|
||||||
|
ctx.cache.set(link, JSON.stringify(single));
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ctx.state.data = {
|
||||||
|
// 源标题,差一个cid相关的标题!
|
||||||
|
title: `${mptitle}`,
|
||||||
|
link: `https://mp.weixin.qq.com/mp/homepage?__biz=${biz}${hidurl}${cidurl}`,
|
||||||
|
item: list.map((item, index) => ({
|
||||||
|
title: `${item.title}`,
|
||||||
|
description: `${item.digest}<br>
|
||||||
|
<img style="max-width: 650px; height: auto; object-fit: contain; width: 100%;" src="${item.cover}"><br><br>${articledata[index].content}`,
|
||||||
|
link: `${item.link}`,
|
||||||
|
author: `${articledata[index].author}`,
|
||||||
|
pubDate: dayjs.unix(item.sendtime).format(),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user