From f1eedb01abd98a47322039ca643bd2bdaca62036 Mon Sep 17 00:00:00 2001 From: youzipi Date: Tue, 19 Jan 2021 06:39:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=BE=8E=E5=9B=A2=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E5=B9=B3=E5=8F=B0=E5=85=AC=E5=91=8A=20(#6719)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add 美团开放平台公告 * feat: add 美团开放平台公告 --- docs/programming.md | 6 ++++ lib/router.js | 3 ++ lib/routes/meituan/open/announce.js | 45 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/routes/meituan/open/announce.js diff --git a/docs/programming.md b/docs/programming.md index ffa493b09b..855b992574 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -665,6 +665,12 @@ GitHub 官方也提供了一些 RSS: +## 美团开放平台 + +### 美团开放平台公告 + + + ## 平安银河实验室 ### posts diff --git a/lib/router.js b/lib/router.js index ea0cf2af06..c1fa3ff1d4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2092,6 +2092,9 @@ router.get('/tianya/comments/:userid', require('./routes/tianya/comments')); router.get('/eleme/open/announce', require('./routes/eleme/open/announce')); router.get('/eleme/open-be/announce', require('./routes/eleme/open-be/announce')); +// 美团开放平台 +router.get('/meituan/open/announce', require('./routes/meituan/open/announce')); + // 微信开放社区 router.get('/wechat-open/community/:type', require('./routes/tencent/wechat/wechat-open/community/announce')); // 微信支付 - 商户平台公告 diff --git a/lib/routes/meituan/open/announce.js b/lib/routes/meituan/open/announce.js new file mode 100644 index 0000000000..e55595f1f6 --- /dev/null +++ b/lib/routes/meituan/open/announce.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://developer.meituan.com/api/v1/announcement/menu-page?docKey=anno-all&pageSize=100&pageNum=1', + }); + const docList = response.data.data.docList; + + const url = 'https://developer.meituan.com/api/v1/doc/content'; + + // https://developer.meituan.com/api/v1/doc/content?docKey=announcement-468 + const articleList = await Promise.all( + docList.map(async (item) => { + const articleUrl = `${url}?docKey=${item.docKey}`; + const cacheKey = `${articleUrl}_${item.modifyTime}`; + + const cache = await ctx.cache.get(cacheKey); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } else { + const articleResp = await got.get(articleUrl); + const article = { + title: item.title, + link: `https://developer.meituan.com/isv/announcement/detail?dockey=anno-all&id=${item.docKey}`, + description: articleResp.data.data.docDataItemDtos[0].content, + pubDate: item.modifyTime, + }; + ctx.cache.set(cacheKey, JSON.stringify(article)); + return Promise.resolve(article); + } + }) + ); + + ctx.state.data = { + title: '美团开放平台-公告', + link: 'https://developer.meituan.com/isv/announcement/list', + item: articleList.map((item) => ({ + title: item.title, + description: item.description, + pubDate: item.modifyTime, + link: item.link, + })), + }; +};