From f87d38160920c48e16c6419caa3378e331a7dad2 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Fri, 31 Jan 2020 09:37:58 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=A1=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E7=9B=B8=E5=85=B3=E8=B7=AF=E7=94=B1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=AE=80=E5=8C=96=20(#3804)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/router.js | 14 ++++---- .../wechat/miniprogram}/release.js | 0 .../wechat/wechat-open/community/announce.js} | 19 ++++++++-- .../wechat/wechat-open/community/question.js} | 24 +++++++------ .../wechat}/wechat-open/pay/announce.js | 0 .../wechat-open/community/xcx-announce.js | 30 ---------------- .../wechat-open/community/xcx-question.js | 35 ------------------- .../wechat-open/community/xyx-announce.js | 30 ---------------- 8 files changed, 35 insertions(+), 117 deletions(-) rename lib/routes/{weixinMiniprogram => tencent/wechat/miniprogram}/release.js (100%) rename lib/routes/{wechat-open/community/pay-announce.js => tencent/wechat/wechat-open/community/announce.js} (60%) rename lib/routes/{wechat-open/community/xyx-question.js => tencent/wechat/wechat-open/community/question.js} (52%) rename lib/routes/{ => tencent/wechat}/wechat-open/pay/announce.js (100%) delete mode 100644 lib/routes/wechat-open/community/xcx-announce.js delete mode 100644 lib/routes/wechat-open/community/xcx-question.js delete mode 100644 lib/routes/wechat-open/community/xyx-announce.js diff --git a/lib/router.js b/lib/router.js index f0fda21373..3a47ed6646 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1790,13 +1790,11 @@ 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')); -// wechat-open -router.get('/wechat-open/community/xcx-announce', require('./routes/wechat-open/community/xcx-announce')); -router.get('/wechat-open/community/xyx-announce', require('./routes/wechat-open/community/xyx-announce')); -router.get('/wechat-open/community/pay-announce', require('./routes/wechat-open/community/pay-announce')); -router.get('/wechat-open/pay/announce', require('./routes/wechat-open/pay/announce')); -router.get('/wechat-open/community/xyx-question/:category', require('./routes/wechat-open/community/xyx-question')); -router.get('/wechat-open/community/xcx-question/:tag', require('./routes/wechat-open/community/xcx-question')); +// 微信开放社区 +router.get('/wechat-open/community/:type', require('./routes/tencent/wechat/wechat-open/community/announce')); +// 微信支付 - 商户平台公告 +router.get('/wechat-open/pay/announce', require('./routes/tencent/wechat/wechat-open/pay/announce')); +router.get('/wechat-open/community/:type/:category', require('./routes/tencent/wechat/wechat-open/community/question')); // 微店 router.get('/weidian/goods/:id', require('./routes/weidian/goods')); @@ -2154,7 +2152,7 @@ router.get('/scala/blog/:part?', require('./routes/scala-blog/scala-blog')); router.get('/minecraft/version', require('./routes/minecraft/version')); // 微信更新日志 -router.get('/weixin/miniprogram/release', require('./routes/weixinMiniprogram/release')); // 基础库更新 +router.get('/weixin/miniprogram/release', require('./routes/tencent/wechat/miniprogram/release')); // 基础库更新 // 武汉肺炎疫情动态 router.get('/coronavirus/caixin', require('./routes/coronavirus/caixin')); diff --git a/lib/routes/weixinMiniprogram/release.js b/lib/routes/tencent/wechat/miniprogram/release.js similarity index 100% rename from lib/routes/weixinMiniprogram/release.js rename to lib/routes/tencent/wechat/miniprogram/release.js diff --git a/lib/routes/wechat-open/community/pay-announce.js b/lib/routes/tencent/wechat/wechat-open/community/announce.js similarity index 60% rename from lib/routes/wechat-open/community/pay-announce.js rename to lib/routes/tencent/wechat/wechat-open/community/announce.js index 650d9c745e..4ced6357cc 100644 --- a/lib/routes/wechat-open/community/pay-announce.js +++ b/lib/routes/tencent/wechat/wechat-open/community/announce.js @@ -2,9 +2,22 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { + let { type } = ctx.params; + let title = '微信开放社区 - '; + if (type.startsWith('pay')) { + type = 'pay'; + title += '微信支付公告'; + } else if (type.startsWith('xcx')) { + type = 'develop'; + title += '小程序公告'; + } else if (type.startsWith('xyx')) { + type = 'minigame'; + title += '小游戏公告'; + } + const link = `https://developers.weixin.qq.com/community/${type}/list/2`; const { data: htmlString } = await got({ method: 'get', - url: 'https://developers.weixin.qq.com/community/pay/list/2', + url: link, }); const $ = cheerio.load(htmlString); const announceList = []; @@ -23,8 +36,8 @@ module.exports = async (ctx) => { }); ctx.state.data = { - title: '微信开放社区-微信支付公告', - link: 'https://developers.weixin.qq.com/community/pay/list/2', + title, + link, item: announceList, }; }; diff --git a/lib/routes/wechat-open/community/xyx-question.js b/lib/routes/tencent/wechat/wechat-open/community/question.js similarity index 52% rename from lib/routes/wechat-open/community/xyx-question.js rename to lib/routes/tencent/wechat/wechat-open/community/question.js index be9d615dfd..73434c49e4 100644 --- a/lib/routes/wechat-open/community/xyx-question.js +++ b/lib/routes/tencent/wechat/wechat-open/community/question.js @@ -1,25 +1,27 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { - const category = ctx.params.category; + const { type, category } = ctx.params; + let url, title; + if (type.startsWith('xcx')) { + url = `https://developers.weixin.qq.com/community/ngi/question/list?page=1&tag=${category}`; + title = `微信开放社区的小程序问题 - ${category}`; + } else if (type.startsWith('xyx')) { + url = `https://developers.weixin.qq.com/community/ngi/timeline/2/1/${category}?page=1&limit=10`; + title = `微信开放社区的小游戏问题 - ${category}`; + } - const response = await got({ - method: 'get', - url: `https://developers.weixin.qq.com/community/ngi/timeline/2/1/${category}?page=1&limit=10`, - headers: { - Referer: `https://developers.weixin.qq.com/community/minigame/question?type=${category}`, - }, - }); + const response = await got.get(url); const data = response.data.data; ctx.state.data = { // 源标题 - title: `微信开放社区的小程序问题 - ${category}`, + title, // 源链接 - link: `https://developers.weixin.qq.com/community/develop/question?tag=${category}`, + link: url, // 源说明 - description: `微信开放社区的小程序问题 - ${category}`, + description: title, // 遍历此前获取的数据 item: data.rows.map((item) => ({ // 文章标题 diff --git a/lib/routes/wechat-open/pay/announce.js b/lib/routes/tencent/wechat/wechat-open/pay/announce.js similarity index 100% rename from lib/routes/wechat-open/pay/announce.js rename to lib/routes/tencent/wechat/wechat-open/pay/announce.js diff --git a/lib/routes/wechat-open/community/xcx-announce.js b/lib/routes/wechat-open/community/xcx-announce.js deleted file mode 100644 index 05e93ad059..0000000000 --- a/lib/routes/wechat-open/community/xcx-announce.js +++ /dev/null @@ -1,30 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const { data: htmlString } = await got({ - method: 'get', - url: 'https://developers.weixin.qq.com/community/develop/list/2', - }); - const $ = cheerio.load(htmlString); - const announceList = []; - $('#article_frame > div > ul > li').each(function() { - const $item = $(this); - const $link = $item.find('a').attr('href'); - const time = $item.find('div > em').text(); - const title = $item.find('h2 > meta').attr('content'); - - announceList.push({ - title: title, - link: `https://developers.weixin.qq.com${$link}`, - description: title, - pubDate: time, - }); - }); - - ctx.state.data = { - title: '微信开放社区-小程序公告', - link: 'https://developers.weixin.qq.com/community/develop/list/2', - item: announceList, - }; -}; diff --git a/lib/routes/wechat-open/community/xcx-question.js b/lib/routes/wechat-open/community/xcx-question.js deleted file mode 100644 index 2be10d023a..0000000000 --- a/lib/routes/wechat-open/community/xcx-question.js +++ /dev/null @@ -1,35 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const tag = ctx.params.tag; - - const response = await got({ - method: 'get', - url: `https://developers.weixin.qq.com/community/ngi/question/list?page=1&tag=${tag}`, - headers: { - Referer: `https://developers.weixin.qq.com/community/develop/question`, - }, - }); - - const data = response.data.data; - - ctx.state.data = { - // 源标题 - title: `微信开放社区的小程序问题 - ${tag}`, - // 源链接 - link: `https://developers.weixin.qq.com/community/develop/question?tag=${tag}`, - // 源说明 - description: `微信开放社区的小程序问题 - ${tag}`, - // 遍历此前获取的数据 - item: data.rows.map((item) => ({ - // 文章标题 - title: item.Title, - // 文章正文 - description: `${item.Content}`, - // 文章发布时间 - pubDate: new Date(item.CreateTime * 1000).toUTCString(), - // 文章链接 - link: `https://developers.weixin.qq.com/community/develop/doc/${item.DocId}`, - })), - }; -}; diff --git a/lib/routes/wechat-open/community/xyx-announce.js b/lib/routes/wechat-open/community/xyx-announce.js deleted file mode 100644 index 9755117568..0000000000 --- a/lib/routes/wechat-open/community/xyx-announce.js +++ /dev/null @@ -1,30 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const { data: htmlString } = await got({ - method: 'get', - url: 'https://developers.weixin.qq.com/community/minigame/list/2', - }); - const $ = cheerio.load(htmlString); - const announceList = []; - $('#article_frame > div > ul > li').each(function() { - const $item = $(this); - const $link = $item.find('a').attr('href'); - const time = $item.find('div > em').text(); - const title = $item.find('h2 > meta').attr('content'); - - announceList.push({ - title: title, - link: `https://developers.weixin.qq.com${$link}`, - description: title, - pubDate: time, - }); - }); - - ctx.state.data = { - title: '微信开放社区-小游戏公告', - link: 'https://developers.weixin.qq.com/community/minigame/list/2', - item: announceList, - }; -};