Authored by 郭成尧

app-udid

... ... @@ -115,10 +115,25 @@ app.use((req, res, next) => {
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
req.app.locals.wap = app.locals.wap; // zookeper对象赋值
// 判断请求是否来自app
req.yoho.isNowApp = /yohonow/i.test(req.get('User-Agent') || '');
req.yoho.isMarsApp = /yohomars/i.test(req.get('User-Agent') || '');
req.yoho.isYohoApp = /YohoBuy/i.test(req.get('User-Agent') || '');
req.yoho.isApp = req.yoho.isMarsApp ||
req.cookies.app_version ||
req.yoho.isNowApp ||
/YohoBuy/i.test(req.get('User-Agent') || '') ||
(req.query.app_version && req.query.app_version !== 'false') ||
(req.query.appVersion && req.query.appVersion !== 'false');
// 独立的 UDID
if (!req.cookies.udid) {
let udid = uuid.v4();
if (req.yoho.isApp && req.query.udid) {
udid = req.query.udid;
}
res.cookie('udid', udid, {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000)
... ...
... ... @@ -54,16 +54,6 @@ module.exports = () => {
// IP 地址
yoho.clientIp = _getClientIp(req);
// 判断请求是否来自app
yoho.isNowApp = /yohonow/i.test(req.get('User-Agent') || '');
yoho.isMarsApp = /yohomars/i.test(req.get('User-Agent') || '');
yoho.isYohoApp = /YohoBuy/i.test(req.get('User-Agent') || '');
yoho.isApp = yoho.isMarsApp ||
req.cookies.app_version ||
yoho.isNowApp ||
/YohoBuy/i.test(req.get('User-Agent') || '') ||
(req.query.app_version && req.query.app_version !== 'false') ||
(req.query.appVersion && req.query.appVersion !== 'false');
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
yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');
yoho.isWeibo = /weibo/i.test(req.get('User-Agent') || '');
... ...