diff --git a/assets/radar-rules.js b/assets/radar-rules.js old mode 100644 new mode 100755 index 6a5c713902..9ff2164899 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -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') : ''}`, + }, + ], + }, }); diff --git a/docs/new-media.md b/docs/new-media.md old mode 100644 new mode 100755 index bc401a6e4f..59eef2aa42 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -990,6 +990,16 @@ Supported sub-sites: +### 公众号栏目 (非推送 & 历史消息) + + + +只适用拥有首页模板 (分享链接带有 homepage) 的公众号。例如从公众号分享出来的链接为 ,`biz` 为 `MzA3MDM3NjE5NQ==`,`hid` 为 `4`。 + +有些页面里会有分栏, `cid` 可以通过元素选择器选中栏目查看`data-index`。如[链接](https://mp.weixin.qq.com/mp/homepage?__biz=MzA3MDM3NjE5NQ==&hid=4)里的 `京都职人` 栏目的 `cid` 为 `0`,`文艺时光` 栏目的 `cid` 为 `2`。如果不清楚的话最左边的栏目为`0`,其右方栏目依次递增 `1`。 + + + ### 公众平台系统公告栏目 diff --git a/lib/router.js b/lib/router.js index 5d11946069..dd7e4babc7 100755 --- a/lib/router.js +++ b/lib/router.js @@ -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/uread/:userid', require('./routes/tencent/wechat/uread')); 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 router.get('/atfd/:locations/:nearby?', require('./routes/atfd/index')); diff --git a/lib/routes/tencent/wechat/mp.js b/lib/routes/tencent/wechat/mp.js new file mode 100755 index 0000000000..d63d16fb03 --- /dev/null +++ b/lib/routes/tencent/wechat/mp.js @@ -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('