diff --git a/docs/social-media.md b/docs/social-media.md index 233c96d116..a174ba4e50 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -1615,11 +1615,11 @@ rule ### 微信公众号 - + ### 抖音短视频 - + ::: warning 注意 免费版账户抖音每天查询次数 20 次,如需增加次数可购买新榜会员或等待未来多账户支持 diff --git a/lib/router.js b/lib/router.js index 7e1abb41e4..e5388b0a88 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3005,8 +3005,8 @@ router.get('/liequtv/room/:id', lazyloadRouteHandler('./routes/liequtv/room')); router.get('/bwu/news', lazyloadRouteHandler('./routes/universities/bwu/news')); // 新榜 -router.get('/newrank/wechat/:wxid', lazyloadRouteHandler('./routes/newrank/wechat')); -router.get('/newrank/douyin/:dyid', lazyloadRouteHandler('./routes/newrank/douyin')); +// router.get('/newrank/wechat/:wxid', lazyloadRouteHandler('./routes/newrank/wechat')); +// router.get('/newrank/douyin/:dyid', lazyloadRouteHandler('./routes/newrank/douyin')); // 漫小肆 router.get('/manxiaosi/book/:id', lazyloadRouteHandler('./routes/manxiaosi/book')); diff --git a/lib/routes/newrank/wechat.js b/lib/routes/newrank/wechat.js deleted file mode 100644 index 5ee1a3de10..0000000000 --- a/lib/routes/newrank/wechat.js +++ /dev/null @@ -1,37 +0,0 @@ -const got = require('@/utils/got'); -const utils = require('./utils'); -const config = require('@/config').value; - -module.exports = async (ctx) => { - const uid = ctx.params.wxid; - const nonce = utils.random_nonce(9); - const response = await got({ - method: 'post', - url: 'https://www.newrank.cn/xdnphb/detail/v1/rank/article/lists', - headers: { - Connection: 'keep-alive', - Cookie: String(config.newrank.cookie), - }, - form: { - account: uid, - nonce, - xyz: utils.decrypt_wechat_detail_xyz(uid, nonce), - }, - }); - const name = response.data.value.user.name; - const realTimeArticles = utils.flatten(response.data.value.realTimeArticles); - const articles = utils.flatten(response.data.value.articles); - const newArticles = realTimeArticles.concat(articles); - const items = newArticles.map((item) => ({ - title: item.title, - description: '', - link: item.url, - pubDate: item.publicTime, - })); - - ctx.state.data = { - title: name + ' - 微信公众号', - link: 'https://www.newrank.cn/new/readDetial?account=' + uid, - item: items, - }; -}; diff --git a/lib/routes/newrank/douyin.js b/lib/v2/newrank/douyin.js similarity index 87% rename from lib/routes/newrank/douyin.js rename to lib/v2/newrank/douyin.js index 55dc86f46b..01a291ce84 100644 --- a/lib/routes/newrank/douyin.js +++ b/lib/v2/newrank/douyin.js @@ -3,10 +3,13 @@ const utils = require('./utils'); const config = require('@/config').value; module.exports = async (ctx) => { + if (!config.newrank || !config.newrank.cookie) { + throw Error('newrank RSS is disabled due to the lack of relevant config'); + } const uid = ctx.params.dyid; const nonce = utils.random_nonce(9); const url_detail = 'https://xd.newrank.cn/xdnphb/nr/cloud/douyin/detail/aweme?xyz=' + utils.decrypt_douyin_detail_xyz(nonce) + '&nonce=' + nonce; - const cookie = String(config.newrank.cookie); + const cookie = config.newrank.cookie; const response_detail = await got({ method: 'post', url: url_detail, diff --git a/lib/v2/newrank/maintainer.js b/lib/v2/newrank/maintainer.js new file mode 100644 index 0000000000..421e3f1f25 --- /dev/null +++ b/lib/v2/newrank/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/douyin/:dyid': ['lessmoe'], + '/wechat/:wxid': ['lessmoe'], +}; diff --git a/lib/v2/newrank/radar.js b/lib/v2/newrank/radar.js new file mode 100644 index 0000000000..04c00473c1 --- /dev/null +++ b/lib/v2/newrank/radar.js @@ -0,0 +1,15 @@ +module.exports = { + 'newrank.cn': { + _name: '新榜', + '.': [ + { + title: '微信公众号', + docs: 'https://docs.rsshub.app/social-media.html#xin-bang', + }, + { + title: '抖音短视频', + docs: 'https://docs.rsshub.app/social-media.html#xin-bang', + }, + ], + }, +}; diff --git a/lib/v2/newrank/router.js b/lib/v2/newrank/router.js new file mode 100644 index 0000000000..5b65992d39 --- /dev/null +++ b/lib/v2/newrank/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/douyin/:dyid', require('./douyin')); + router.get('/wechat/:wxid', require('./wechat')); +}; diff --git a/lib/routes/newrank/utils.js b/lib/v2/newrank/utils.js similarity index 100% rename from lib/routes/newrank/utils.js rename to lib/v2/newrank/utils.js diff --git a/lib/v2/newrank/wechat.js b/lib/v2/newrank/wechat.js new file mode 100644 index 0000000000..f92b6a0809 --- /dev/null +++ b/lib/v2/newrank/wechat.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const { finishArticleItem } = require('@/utils/wechat-mp'); +const cheerio = require('cheerio'); +const utils = require('./utils'); +const config = require('@/config').value; + +module.exports = async (ctx) => { + if (!config.newrank || !config.newrank.cookie) { + throw Error('newrank RSS is disabled due to the lack of relevant config'); + } + const uid = ctx.params.wxid; + const nonce = utils.random_nonce(9); + const { data: summaryHTML } = await got({ + method: 'get', + url: `https://www.newrank.cn/new/readDetial?account=${uid}`, + headers: { + Connection: 'keep-alive', + Cookie: config.newrank.cookie, + }, + }); + const summary$ = cheerio.load(summaryHTML); + const mainsrc = summary$('script') + .toArray() + .find((item) => (item.attribs.src || '').startsWith('/new/static/js/main.')).attribs.src; + const { data: mainScript } = await got({ + method: 'get', + url: `https://www.newrank.cn${mainsrc}`, + }); + const N_TOKEN_match = mainScript.match(/"N-Token":"([^"]+)/); + if (!N_TOKEN_match) { + throw Error('Cannot find n-token'); + } + const N_TOKEN = N_TOKEN_match[1]; + const response = await got({ + method: 'post', + url: 'https://gw.newrank.cn/api/wechat/xdnphb/detail/v1/rank/article/lists', + headers: { + Connection: 'keep-alive', + Cookie: config.newrank.cookie, + 'n-token': N_TOKEN, + }, + form: { + account: uid, + nonce, + xyz: utils.decrypt_wechat_detail_xyz(uid, nonce), + }, + }); + const name = response.data.value.user.name; + const realTimeArticles = utils.flatten(response.data.value.realTimeArticles); + const articles = utils.flatten(response.data.value.articles); + const newArticles = realTimeArticles.concat(articles); + const items = newArticles.map((item) => ({ + title: item.title, + description: '', + link: item.url, + pubDate: item.publicTime, + })); + await Promise.all(items.map((item) => finishArticleItem(ctx, item))); + + ctx.state.data = { + title: name + ' - 微信公众号', + link: `https://www.newrank.cn/new/readDetial?account=${uid}`, + item: items, + }; +};