Authored by 郭成尧

app-udid

@@ -115,10 +115,25 @@ app.use((req, res, next) => { @@ -115,10 +115,25 @@ app.use((req, res, next) => {
115 req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 115 req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
116 req.app.locals.wap = app.locals.wap; // zookeper对象赋值 116 req.app.locals.wap = app.locals.wap; // zookeper对象赋值
117 117
  118 + // 判断请求是否来自app
  119 + req.yoho.isNowApp = /yohonow/i.test(req.get('User-Agent') || '');
  120 + req.yoho.isMarsApp = /yohomars/i.test(req.get('User-Agent') || '');
  121 + req.yoho.isYohoApp = /YohoBuy/i.test(req.get('User-Agent') || '');
  122 + req.yoho.isApp = req.yoho.isMarsApp ||
  123 + req.cookies.app_version ||
  124 + req.yoho.isNowApp ||
  125 + /YohoBuy/i.test(req.get('User-Agent') || '') ||
  126 + (req.query.app_version && req.query.app_version !== 'false') ||
  127 + (req.query.appVersion && req.query.appVersion !== 'false');
  128 +
118 // 独立的 UDID 129 // 独立的 UDID
119 if (!req.cookies.udid) { 130 if (!req.cookies.udid) {
120 let udid = uuid.v4(); 131 let udid = uuid.v4();
121 132
  133 + if (req.yoho.isApp && req.query.udid) {
  134 + udid = req.query.udid;
  135 + }
  136 +
122 res.cookie('udid', udid, { 137 res.cookie('udid', udid, {
123 domain: 'yohobuy.com', 138 domain: 'yohobuy.com',
124 expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) 139 expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000)
@@ -54,16 +54,6 @@ module.exports = () => { @@ -54,16 +54,6 @@ module.exports = () => {
54 // IP 地址 54 // IP 地址
55 yoho.clientIp = _getClientIp(req); 55 yoho.clientIp = _getClientIp(req);
56 56
57 - // 判断请求是否来自app  
58 - yoho.isNowApp = /yohonow/i.test(req.get('User-Agent') || '');  
59 - yoho.isMarsApp = /yohomars/i.test(req.get('User-Agent') || '');  
60 - yoho.isYohoApp = /YohoBuy/i.test(req.get('User-Agent') || '');  
61 - yoho.isApp = yoho.isMarsApp ||  
62 - req.cookies.app_version ||  
63 - yoho.isNowApp ||  
64 - /YohoBuy/i.test(req.get('User-Agent') || '') ||  
65 - (req.query.app_version && req.query.app_version !== 'false') ||  
66 - (req.query.appVersion && req.query.appVersion !== 'false');  
67 yoho.isMobile = /(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i.test(req.get('User-Agent') || ''); // eslint-disable-line 57 yoho.isMobile = /(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i.test(req.get('User-Agent') || ''); // eslint-disable-line
68 yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || ''); 58 yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');
69 yoho.isWeibo = /weibo/i.test(req.get('User-Agent') || ''); 59 yoho.isWeibo = /weibo/i.test(req.get('User-Agent') || '');