Committed by
shuaiguo
clienttype
Showing
2 changed files
with
29 additions
and
6 deletions
@@ -38,15 +38,16 @@ module.exports = (req, res, next) => { | @@ -38,15 +38,16 @@ module.exports = (req, res, next) => { | ||
38 | req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 | 38 | req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 |
39 | 39 | ||
40 | // 判断请求是否来自app | 40 | // 判断请求是否来自app |
41 | - let userAgent = req.get('User-Agent'); | 41 | + let userAgent = req.get('User-Agent') || ''; |
42 | + | ||
42 | 43 | ||
43 | // 判断请求是否来自app | 44 | // 判断请求是否来自app |
44 | - req.yoho.isAliApp = /AliApp/i.test(userAgent || ''); | ||
45 | - req.yoho.isMiniApp = /miniProgram/i.test(userAgent || '') || | 45 | + req.yoho.isAliApp = /AliApp/i.test(userAgent); |
46 | + req.yoho.isMiniApp = /miniProgram/i.test(userAgent) || | ||
46 | req.query.client_type === 'miniapp'; | 47 | req.query.client_type === 'miniapp'; |
47 | - req.yoho.isNowApp = /yohonow/i.test(userAgent || ''); | ||
48 | - req.yoho.isMarsApp = /yohomars/i.test(userAgent || ''); | ||
49 | - req.yoho.isYohoApp = /YohoBuy/i.test(userAgent || ''); | 48 | + req.yoho.isNowApp = /yohonow/i.test(userAgent); |
49 | + req.yoho.isMarsApp = /yohomars/i.test(userAgent); | ||
50 | + req.yoho.isYohoApp = /YohoBuy/i.test(userAgent); | ||
50 | req.yoho.isApp = req.yoho.isMiniApp || | 51 | req.yoho.isApp = req.yoho.isMiniApp || |
51 | req.yoho.isNowApp || | 52 | req.yoho.isNowApp || |
52 | req.yoho.isMarsApp || | 53 | req.yoho.isMarsApp || |
@@ -54,6 +55,27 @@ module.exports = (req, res, next) => { | @@ -54,6 +55,27 @@ module.exports = (req, res, next) => { | ||
54 | req.yoho.isiOS = /(iPhone|iPad|iPod|iOS)/i.test(userAgent); | 55 | req.yoho.isiOS = /(iPhone|iPad|iPod|iOS)/i.test(userAgent); |
55 | req.yoho.isAndroid = /Android/i.test(userAgent); | 56 | req.yoho.isAndroid = /Android/i.test(userAgent); |
56 | 57 | ||
58 | + let clientType = ''; | ||
59 | + | ||
60 | + if (req.yoho.isAliApp) { | ||
61 | + clientType = 'AliApp_'; | ||
62 | + } else if (req.yoho.isApp) { | ||
63 | + clientType = 'YohoApp_'; | ||
64 | + } else { | ||
65 | + clientType = 'Web_'; | ||
66 | + } | ||
67 | + | ||
68 | + if (req.yoho.isiOS) { | ||
69 | + clientType += 'iOS'; | ||
70 | + } else if (req.yoho.isAndroid) { | ||
71 | + clientType += 'Android'; | ||
72 | + } else { | ||
73 | + clientType += 'unknown'; | ||
74 | + } | ||
75 | + | ||
76 | + req.yoho.clientType = clientType | ||
77 | + | ||
78 | + | ||
57 | // client ip | 79 | // client ip |
58 | req.yoho.clientIp = _getClientIp(req); | 80 | req.yoho.clientIp = _getClientIp(req); |
59 | 81 |
@@ -142,6 +142,7 @@ const render = (route) => { | @@ -142,6 +142,7 @@ const render = (route) => { | ||
142 | path: req.url, | 142 | path: req.url, |
143 | uid: req.user.uid, | 143 | uid: req.user.uid, |
144 | udid: req.cookies.udid || '', | 144 | udid: req.cookies.udid || '', |
145 | + clientType: req.yoho.clientType || '', | ||
145 | ua: req.get('user-agent'), | 146 | ua: req.get('user-agent'), |
146 | time: new Date() | 147 | time: new Date() |
147 | })); | 148 | })); |
-
Please register or login to post a comment