diff --git a/docs/README.md b/docs/README.md index 4820ae9eb..11f276eb4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2185,6 +2185,30 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 +### 京东众筹 + + + +类型 + +| 全部 | 科技 | 美食 | 家电 | 设计 | 娱乐 | 文化 | 公益 | 其他 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| all | kj | ms | jd | sj | yl | wh | gy | qt | + +状态 + +| 全部 | 预热中 | 众筹中 | 众筹成功 | 项目成功 | +| ---- | ------ | ------ | -------- | -------- | +| all | yrz | zcz | zccg | xmcg | + +排序方式 + +| 综合推荐 | 最新上线 | 金额最多 | 支持最多 | 即将结束 | +| -------- | -------- | -------- | -------- | -------- | +| zhtj | zxsx | jezg | zczd | jjjs | + + + ## 游戏资讯 ### 3DMGame diff --git a/lib/router.js b/lib/router.js index eb16c63d3..8b85f765e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -954,4 +954,6 @@ router.get('/patchwork.kernel.org/comments/:id', require('./routes/patchwork.ker // qdaily router.get('/qdaily', require('./routes/qdaily/index')); +// 京东众筹 +router.get('/jingdong/zhongchou/:type/:status/:sort', require('./routes/jingdong/zhongchou')); module.exports = router; diff --git a/lib/routes/jingdong/zhongchou.js b/lib/routes/jingdong/zhongchou.js new file mode 100644 index 000000000..8a52ca32d --- /dev/null +++ b/lib/routes/jingdong/zhongchou.js @@ -0,0 +1,95 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const url = require('url'); + +const contentUrl = 'https://z.jd.com/bigger/search.html'; +const host = 'https://z.jd.com/'; +const typeCodes = new Map([ + ['all', { title: '京东众筹 -- 全部', code: '' }], + ['kj', { title: '京东众筹 -- 科技', code: 10 }], + ['ms', { title: '京东众筹 -- 美食', code: 36 }], + ['jd', { title: '京东众筹 -- 家电', code: 37 }], + ['sj', { title: '京东众筹 -- 设计', code: 12 }], + ['yl', { title: '京东众筹 -- 娱乐', code: 11 }], + ['wh', { title: '京东众筹 -- 文化', code: 38 }], + ['gy', { title: '京东众筹 -- 公益', code: 13 }], + ['qt', { title: '京东众筹 -- 其他', code: 14 }], +]); + +const statusCodes = { + all: '', + yrz: 1, + zcz: 2, + zccg: 4, + xmcg: 8, +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'all'; + const status = ctx.params.status || 'all'; + const sort = ctx.params.sort || 'zxsx'; + + const title = typeCodes.get(type).title; + const typeCode = typeCodes.get(type).code; + const statusCode = statusCodes[status]; + + const params = { + sort: sort, + }; + if (typeCode !== '') { + params.categoryId = typeCode; + } + if (statusCode !== '') { + params.status = statusCode; + } + const response = await axios({ + method: 'post', + url: contentUrl, + headers: { + 'Content-type': 'application/x-www-form-urlencoded', + }, + params: params, + }); + + const $ = cheerio.load(response.data); + + const out = $('body > div.wrap.mt20 > div.l-info > div.l-result > ul > li') + .slice(0, 10) + .map(function() { + const image = + 'https:' + + $(this) + .find('a.link-pic > img') + .attr('src'); + const information = $(this) + .find('div.p-outter > div.p-items > ul') + .html() + .trim(); + const description = `
${information}`; + + const info = { + link: url.resolve( + host, + $(this) + .find('a.link-pic') + .attr('href') + ), + description: description, + title: + $(this) + .find('div.i-tits.no-color-choose > a > h4') + .text() || + $(this) + .find('div.i-tits > a > h4') + .text(), + }; + return info; + }) + .get(); + + ctx.state.data = { + title: title, + link: host, + item: out, + }; +};