From bbe99c559c2e9c5da5230e39ce75efd19b76c376 Mon Sep 17 00:00:00 2001 From: Ethan H Date: Fri, 22 Mar 2019 17:52:56 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A4=A7=E4=BC=97=E7=82=B9=E8=AF=84=20#1?= =?UTF-8?q?708=20(#1776)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add 大众点评 #1708 * 改用API查询用户信息 --- docs/README.md | 4 ++ lib/router.js | 3 ++ lib/routes/dianping/user.js | 96 +++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 lib/routes/dianping/user.js diff --git a/docs/README.md b/docs/README.md index 2dc011cad..cb5365cdd 100755 --- a/docs/README.md +++ b/docs/README.md @@ -3230,6 +3230,10 @@ type 为 all 时,category 参数不支持 cost 和 free +### 大众点评 + + + ### 半月谈 diff --git a/lib/router.js b/lib/router.js index 32dc28174..9e2516129 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1175,6 +1175,9 @@ router.get('/zjgsu/tzgg', require('./routes/universities/zjgsu/tzgg/scripts')); router.get('/zjgsu/gsgg', require('./routes/universities/zjgsu/gsgg/scripts')); router.get('/zjgsu/xszq', require('./routes/universities/zjgsu/xszq/scripts')); +// 大众点评 +router.get('/dianping/user/:id?', require('./routes/dianping/user')); + // 半月谈 router.get('/banyuetan/:name', require('./routes/banyuetan')); diff --git a/lib/routes/dianping/user.js b/lib/routes/dianping/user.js new file mode 100644 index 000000000..2f3a854d1 --- /dev/null +++ b/lib/routes/dianping/user.js @@ -0,0 +1,96 @@ +const axios = require('../../utils/axios'); +const date = require('../../utils/date'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'; + const userPage = `https://m.dianping.com/userprofile/${id}`; + + const pageResponse = await axios({ + method: 'get', + url: userPage, + headers: { + 'User-Agent': userAgent, + }, + }); + const nickNameReg = /window\.nickName = "(.*?)"/g; + const nickName = nickNameReg.exec(pageResponse.data)[1]; + + const response = await axios({ + method: 'get', + url: `https://m.dianping.com/member/ajax/NobleUserFeeds?userId=${id}`, + headers: { + 'User-Agent': userAgent, + Referer: userPage, + }, + }); + + const data = response.data.data; + const starMap = { + 0: '无', + 10: '一星', + 20: '二星', + 30: '三星', + 35: '三星半', + 40: '四星', + 45: '四星半', + 50: '五星', + }; + const out = data.map(function(item) { + let link = ''; + let title = ''; + let content = ''; + const pubDate = date(item.addTime); + const poi = item.poi ? `地点:${item.poi.name} - ${item.poi.regionCategory}` : ''; + const poiName = item.poi ? item.poi.name : ''; + if (item.feedType === 1101) { + // 签到成功 + link = `https://m.dianping.com/ugcdetail/${item.mainId}?sceneType=0&bizType=3`; + content = poi; + title = `签到成功: ${poiName} `; + } else if (item.feedType === 101) { + // 发布点评 + link = `https://m.dianping.com/ugcdetail/${item.mainId}?sceneType=0&bizType=1`; + content = item.content.replace(/\n+/g, '
') + '
'; + content += `评分:${starMap[item.star]}
`; + content += poi + '
'; + content += item.pictureList + ? item.pictureList + .map(function(ele) { + return ``; + }) + .join('
') + : ''; + title = `发布点评: ${poiName}`; + } else if (item.feedType === 4208) { + // 发布攻略 + link = `https://m.dianping.com/cityinsight/${item.mainId}`; + content = item.content.replace(/\n+/g, '
') + '
'; + content += poi + '
'; + content += item.pictureList + ? item.pictureList + .map(function(ele) { + return ``; + }) + .join('
') + : ''; + title = `发布攻略: ${poiName}`; + } + + const info = { + description: content, + title: title, + link: link, + pubDate: pubDate, + }; + return info; + }); + + ctx.state.data = { + title: `大众点评 - ${nickName}`, + link: userPage, + description: `大众点评 - ${nickName}`, + item: out, + }; +};