diff --git a/docs/README.md b/docs/README.md
index 6b59e1824..eef4ac897 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1550,9 +1550,11 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### 小米
-
+
-
+
+
+
## 网络小说
@@ -1880,7 +1882,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### 后续
-
+
### 老司机
diff --git a/router.js b/router.js
index b07a345dc..7e72dd8cc 100644
--- a/router.js
+++ b/router.js
@@ -374,6 +374,7 @@ router.get('/hexo/next/:url', require('./routes/hexo/next'));
// 小米
router.get('/mi/crowdfunding', require('./routes/mi/crowdfunding'));
+router.get('/mi/youpin/crowdfunding', require('./routes/mi/youpin/crowdfunding'));
router.get('/mi/youpin/new', require('./routes/mi/youpin/new'));
// Keep
diff --git a/routes/mi/crowdfunding.js b/routes/mi/crowdfunding.js
index c7a2a5d9d..dead40966 100644
--- a/routes/mi/crowdfunding.js
+++ b/routes/mi/crowdfunding.js
@@ -1,48 +1,29 @@
const axios = require('../../utils/axios');
module.exports = async (ctx) => {
- const baseUrl = 'https://home.mi.com/app/shop/content?id=s8939d03918810635';
const response = await axios({
- method: 'get',
- url: baseUrl,
+ method: 'post',
+ url: 'http://api.m.mi.com/v1/microwd/home',
+ headers: {
+ 'Mishop-Client-Id': '180100031055',
+ 'User-Agent': 'MiShop/4.3.68 (iPhone; iOS 12.0.1; Scale/3.00)',
+ 'IOS-App-Version': '4.3.68',
+ 'IOS-Version': 'system=12.0.1&device=iPhone10,3',
+ },
+ });
+ let list = [];
+ response.data.data.list.forEach((item) => {
+ list = list.concat(item.items);
});
-
- const data = response.data.match(/,gid:(\d*),src:"(.+?)"/g).map((item) => ({
- gid: item.match(/gid:(\d*)/)[1],
- img: item.match(/src:"(.+?)"/)[1],
- }));
-
- const out = await Promise.all(
- data.map(async (item) => {
- const key = `microwdfunding${item.gid}`;
- const value = await ctx.cache.get(key);
- let result;
- if (value) {
- result = JSON.parse(value);
- } else {
- const response = await axios({
- method: 'get',
- url: `https://home.mi.com/app/shop/jsonp?k=test&m=Product&a=GetDetail&p={%22gid%22:${item.gid}}&_=${+new Date()}&callback=Zepto1532846359142`,
- headers: {
- Referer: baseUrl,
- },
- });
- const data = JSON.parse(response.data.match(/^Zepto1532846359142\((.*)\);$/)[1]).data || {};
- result = {
- title: data.goods.name,
- description: `${data.goods.summary}
${data.goods.price_min / 100}元
`,
- pubDate: new Date(data.crowdfunding.start * 1000).toUTCString(),
- link: `https://youpin.mi.com/detail?gid=${item.gid}`,
- };
- ctx.cache.set(key, JSON.stringify(result), 12 * 60 * 60);
- }
- return Promise.resolve(result);
- })
- );
ctx.state.data = {
title: '小米众筹',
- link: baseUrl,
- item: out,
+ link: '',
+ item:
+ list &&
+ list.map((item) => ({
+ title: item.product_name,
+ description: `
价格:${item.product_price}元`,
+ })),
};
};
diff --git a/routes/mi/youpin/crowdfunding.js b/routes/mi/youpin/crowdfunding.js
new file mode 100644
index 000000000..087a845fc
--- /dev/null
+++ b/routes/mi/youpin/crowdfunding.js
@@ -0,0 +1,18 @@
+const axios = require('../../../utils/axios');
+const utils = require('./utils');
+
+module.exports = async (ctx) => {
+ const response = await axios({
+ method: 'get',
+ url: 'https://home.mi.com/lasagne/page/5',
+ });
+
+ const data = response.data.floors;
+
+ ctx.state.data = {
+ title: '小米有品众筹',
+ link: 'https://home.mi.com/crowdfunding?&pageid=5',
+ description: '小米有品众筹',
+ item: utils.generateData(data),
+ };
+};
diff --git a/routes/mi/youpin/new.js b/routes/mi/youpin/new.js
index 18c030f5b..199030827 100644
--- a/routes/mi/youpin/new.js
+++ b/routes/mi/youpin/new.js
@@ -1,4 +1,5 @@
const axios = require('../../../utils/axios');
+const utils = require('./utils');
module.exports = async (ctx) => {
const response = await axios({
@@ -9,35 +10,9 @@ module.exports = async (ctx) => {
const data = response.data.floors;
ctx.state.data = {
- title: '有品-每日上新',
+ title: '小米有品每日上新',
link: 'https://home.mi.com/newproduct?pageid=4',
- description: '有品-每日上新',
- item: data.reduce((acc, item) => {
- let goodsList = [];
-
- if (item.data.result) {
- goodsList = item.data.result.goods_list;
- } else if (item.data.tabs) {
- goodsList = item.data.tabs.reduce((acc, tab) => {
- if (tab.result) {
- tab.result.goods_list.forEach((goods) => goods);
- }
-
- return acc;
- }, []);
- }
-
- goodsList.forEach((goods) => {
- const img = goods.pic_url;
- acc.push({
- title: goods.name,
- description: `
${goods.summary}
价格:${goods.market_price / 100}元`,
- link: goods.jump_url,
- pubDate: new Date(goods.first_release_time * 1000).toUTCString(),
- });
- });
-
- return acc;
- }, []),
+ description: '小米有品每日上新',
+ item: utils.generateData(data),
};
};
diff --git a/routes/mi/youpin/utils.js b/routes/mi/youpin/utils.js
new file mode 100644
index 000000000..49a88f9b9
--- /dev/null
+++ b/routes/mi/youpin/utils.js
@@ -0,0 +1,30 @@
+module.exports = {
+ generateData: (data) =>
+ data.reduce((acc, item) => {
+ let goodsList = [];
+
+ if (item.data.result) {
+ goodsList = item.data.result.goods_list;
+ } else if (item.data.tabs) {
+ goodsList = item.data.tabs.reduce((acc, tab) => {
+ if (tab.result) {
+ tab.result.goods_list.forEach((goods) => goods);
+ }
+
+ return acc;
+ }, []);
+ }
+
+ goodsList.forEach((goods) => {
+ const img = goods.pic_url;
+ acc.push({
+ title: goods.name,
+ description: `
${goods.summary}
价格:${goods.market_price / 100}元`,
+ link: goods.jump_url,
+ pubDate: new Date(goods.first_release_time * 1000).toUTCString(),
+ });
+ });
+
+ return acc;
+ }, []),
+};