feat: 微信开放平台相关路由代码简化 (#3804)

This commit is contained in:
Henry Wang
2020-01-31 09:37:58 +00:00
committed by GitHub
parent a86d033ad1
commit f87d381609
8 changed files with 35 additions and 117 deletions

View File

@@ -0,0 +1,37 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
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.get(url);
const data = response.data.data;
ctx.state.data = {
// 源标题
title,
// 源链接
link: url,
// 源说明
description: title,
// 遍历此前获取的数据
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}`,
})),
};
};