From 3b442f3c84967114cedba7ee615c960de5119e1c Mon Sep 17 00:00:00 2001 From: Cloud Date: Sun, 8 Sep 2019 12:47:48 +0800 Subject: [PATCH] feat: youzan/weidian title replace userid to shopname (#3017) --- lib/routes/weidian/goods.js | 7 ++++++- lib/routes/youzan/goods.js | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/routes/weidian/goods.js b/lib/routes/weidian/goods.js index f547a1a33..81dc70e55 100644 --- a/lib/routes/weidian/goods.js +++ b/lib/routes/weidian/goods.js @@ -1,4 +1,5 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const id = String(ctx.params.id); @@ -6,6 +7,10 @@ module.exports = async (ctx) => { const link = `https://weidian.com/?userid=${id}`; const api_link = `https://thor.weidian.com/ares/shop.getItemsInShop/1.0?param={"shopId":"${id}","tabId":3,"sortOrder":"desc","limit":20,"page":1}`; + const shopresponse = await got.get(link); + const $ = cheerio.load(shopresponse.data); + const shopname = $('.shop-name').text(); + const response = await got({ method: 'get', url: api_link, @@ -25,7 +30,7 @@ module.exports = async (ctx) => { }); ctx.state.data = { - title: `${id} 商铺上新`, + title: `${shopname || id} 商铺上新`, link: link, item: out, }; diff --git a/lib/routes/youzan/goods.js b/lib/routes/youzan/goods.js index 2dc471530..f42db63dc 100644 --- a/lib/routes/youzan/goods.js +++ b/lib/routes/youzan/goods.js @@ -1,11 +1,16 @@ const got = require('@/utils/got'); +const cheerio = require('cheerio'); module.exports = async (ctx) => { const id = String(ctx.params.id); - const link = `https://h5.youzan.com/wscshop/feature/goods/all?kdt_id=${id}`; + const link = `https://h5.youzan.com/wscshop/showcase/homepage?kdt_id=${id}`; const api_link = `https://h5.youzan.com/wscshop/showcase/goods/allGoods.json?pageSize=20&page=1&offlineId=0&order=&order_by=createdTime&kdt_id=${id}`; + const shopresponse = await got.get(link); + const $ = cheerio.load(shopresponse.data); + const shopname = $('title').text(); + const response = await got({ method: 'get', url: api_link, @@ -25,7 +30,7 @@ module.exports = async (ctx) => { }); ctx.state.data = { - title: `${id} 商铺上新`, + title: `${shopname || id} 商铺上新`, link: link, item: out, };