diff --git a/docs/finance.md b/docs/finance.md index 900779118..0b3b171cd 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -102,6 +102,12 @@ pageClass: routes +## 东方财富 + +### 天天基金用户动态 + + + ## 富途牛牛 ### 要闻 @@ -203,12 +209,6 @@ pageClass: routes -## 天天基金 - -### 用户动态 - - - ## 乌拉邦 ### 最新研报 diff --git a/lib/router.js b/lib/router.js index 6cc37e781..e078cf45e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2682,8 +2682,8 @@ router.get('/ccnuwu', lazyloadRouteHandler('./routes/universities/ccnu/ccnuwu')) // WEEX router.get('/weexcn/news/:typeid', lazyloadRouteHandler('./routes/weexcn/index')); -// 天天基金 -router.get('/eastmoney/user/:uid', lazyloadRouteHandler('./routes/eastmoney/user')); +// 天天基金 migrated to v2 +// router.get('/eastmoney/ttjj/user/:uid', lazyloadRouteHandler('./routes/eastmoney/ttjj/user')); // 紳士漫畫 router.get('/ssmh', lazyloadRouteHandler('./routes/ssmh')); diff --git a/lib/routes/eastmoney/user.js b/lib/routes/eastmoney/user.js deleted file mode 100644 index 6398d8c61..000000000 --- a/lib/routes/eastmoney/user.js +++ /dev/null @@ -1,30 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const uid = ctx.params.uid; - const response = await got({ - method: 'get', - headers: { - Accept: '*/*', - Host: 'i.eastmoney.com', - 'Accept-Encoding': 'gzip, deflate, br', - 'Cache-Control': 'no-cache', - }, - url: `https://i.eastmoney.com/api/ta/UserPostList?p=1&ps=20&uid=${uid}`, - }); - - const data = response.data.data.re; - const username = data[0].post_user.user_nickname; - - ctx.state.data = { - title: `天天基金-${username}的主页`, - link: `https://i.eastmoney.com//${uid}`, - description: `${username} 的 动态`, - item: data.map((item) => ({ - title: item.post_title, - description: item.post_content, - pubDate: item.post_display_time, - link: `http://guba.eastmoney.com/news,${item.code_name},${item.post_id}.html`, - })), - }; -}; diff --git a/lib/v2/eastmoney/radar.js b/lib/v2/eastmoney/radar.js new file mode 100644 index 000000000..f738351e2 --- /dev/null +++ b/lib/v2/eastmoney/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'eastmoney.com': { + _name: '东方财富', + fundbarmob: [ + { + title: '天天基金用户动态', + docs: 'https://docs.rsshub.app/finance.html#dong-fang-cai-fu', + source: ['/'], + target: (_param, url) => `/eastmoney/ttjj/user/${new URL(url).searchParams.get('userid')}`, + }, + ], + }, +}; diff --git a/lib/v2/eastmoney/router.js b/lib/v2/eastmoney/router.js new file mode 100644 index 000000000..1bd4ddbd7 --- /dev/null +++ b/lib/v2/eastmoney/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/ttjj/user/:uid', require('./ttjj/user')); +}; diff --git a/lib/v2/eastmoney/ttjj/user.js b/lib/v2/eastmoney/ttjj/user.js new file mode 100644 index 000000000..60d14703b --- /dev/null +++ b/lib/v2/eastmoney/ttjj/user.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + + const urlPrefix = 'https://jijinbaapi.eastmoney.com/gubaapi/v3/read'; + + const userProfileUrl = `${urlPrefix}/User/UserInfo.ashx?ServerVersion=1.0.0&PhoneType=windows&Location=zh-CN&ctoken=&utoken=&deviceid=000000&ps=8&plat=Wap&product=Fund&version=201&followuid=`; + const userProfileResponse = await got(`${userProfileUrl}${uid}`); + const username = userProfileResponse.data.user_nickname || '不存在的用户'; + + const userPostListUrl = `${urlPrefix}/Article/Post/UserPostList.ashx`; + + const listResponse = await got({ + method: 'post', + url: userPostListUrl, + headers: { + Accept: 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + form: { + uid, + deviceId: 666666, + version: 201, + p: 1, + ps: 20, + }, + }); + + const data = listResponse.data.re; + + const userArticleUrl = `${urlPrefix}/Article/Post/ArticleContent.ashx`; + + const result = await Promise.all( + data.map((item) => + ctx.cache.tryGet(userArticleUrl + item.post_id, async () => { + const detailResponse = await got({ + method: 'post', + url: userArticleUrl, + headers: { + Accept: 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: `postid=${item.post_id}&ServerVersion=1.0.0&PhoneType=windows&Location=zh-CN&ctoken=&utoken=&deviceId=000000&userId=&plat=Wap&product=Fund&version=201`, + }); + const description = detailResponse.data.post.post_content; + const single = { + title: item.post_title, + description, + pubDate: timezone(parseDate(item.post_display_time, 'YYYY-MM-DD HH:mm:ss'), +8), + link: `https://fundbarmob.eastmoney.com/index.html?goPage=articleView&lastPage=personDetailView&aid=${item.post_id}`, + }; + return single; + }) + ) + ); + ctx.state.data = { + title: `天天基金-${username}的主页`, + link: `https://fundbarmob.eastmoney.com/index.html?goPage=personDetailView&userid=${uid}`, + description: `${username} 的动态`, + item: result, + }; +};