Authored by 陈峰

Merge branch 'feature/session2' into 'release/5.6'

Feature/session2



See merge request !488
... ... @@ -113,13 +113,10 @@ const getUser = (uid) => {
const getPlatForm = (req) => {
let userAgent = req.get('User-Agent');
let yoho = {};
let uids = req.get('User-Agent').match(/uid=([^;]+)/i);
let versions = req.get('User-Agent').match(/app_version=([^;]+)/i);
let arrs = [];
let isNewVersion = false;
const isProduction = process.env.NODE_ENV === 'production';
let sessionKey = _.get(req, 'user.uid.sessionKey');
let uid;
... ... @@ -156,16 +153,7 @@ const getPlatForm = (req) => {
if (isProduction) {
yoho.http = 'https:';
}
uid = uids && uids.length === 2 ? uids[1] : ''; // 8041246
uid = req.user.uid || uid || req.query.uid || req.cookies.studentUID || '';
if (uid) {
yoho.uid = {
toString: () => {
return uid.toString();
},
sessionKey
};
}
yoho.uid = req.user.uid;
yoho.isLogin = yoho.uid ? true : false;
return co(function*() {
let data = yield getUser(yoho.uid);
... ...
... ... @@ -17,7 +17,7 @@ function humanNum_wan(num) {
exports.beforeIn = (req, res, next) => {
// 将APP登录状态正常化
if (req.yoho.isApp) {
if (req.yoho.isApp && !req.user.uid) {
req.user.uid = req.user.uid || req.query.uid;
}
... ...
... ... @@ -26,7 +26,7 @@ exports.checkIsStudent = (req, res, next) => {
exports.beforeIn = (req, res, next) => {
// 将APP登录状态正常化
if (req.yoho.isApp) {
if (req.yoho.isApp && !req.user.uid) {
req.user.uid = req.user.uid || req.query.uid;
}
... ...
... ... @@ -10,7 +10,10 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
// 服务器报错页面
const _serverCrash = (res, params) => {
const _serverCrash = (res, params, err, next) => {
if (err && err.code === 401) {
return next(err);
}
params.title = params.title || '有货分期';
res.render('installment/server-crash', params);
};
... ... @@ -27,7 +30,7 @@ const _banksInit = () => {
};
// 还款列表公共处理块
const _repaymentList = (req, res, opt, params) => {
const _repaymentList = (req, res, next, opt, params) => {
params = _.assign({
uid: req.user.uid
}, params);
... ... @@ -39,16 +42,16 @@ const _repaymentList = (req, res, opt, params) => {
isInstallmentPage: true,
data: result
}, opt));
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: opt.title
});
}, err, next);
});
};
// 开通分期首页
const index = (req, res) => {
const index = (req, res, next) => {
let uid = req.user.uid;
Promise.all([
... ... @@ -136,15 +139,15 @@ const index = (req, res) => {
isInstallmentPage: true,
title: '有货分期'
}, result));
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
// ajax 请求分期专享商品
const getInstallmentGoods = (req, res) => {
const getInstallmentGoods = (req, res, next) => {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
... ... @@ -162,15 +165,15 @@ const getInstallmentGoods = (req, res) => {
} else {
res.json();
}
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
// 开通结果显示
const review = (req, res) => {
const review = (req, res, next) => {
let openStatus = req.query.status || false;
let uid = req.user.uid;
let data = {
... ... @@ -214,10 +217,10 @@ const review = (req, res) => {
})
}
}, data));
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
} else {
... ... @@ -249,8 +252,8 @@ const review = (req, res) => {
};
// 逾期未还款列表
const overdueList = (req, res) => {
_repaymentList(req, res, {
const overdueList = (req, res, next) => {
_repaymentList(req, res, next, {
title: '逾期未还金额',
posId: 1
}, {
... ... @@ -259,8 +262,8 @@ const overdueList = (req, res) => {
};
// 7日待还款列表
const sevenDayList = (req, res) => {
_repaymentList(req, res, {
const sevenDayList = (req, res, next) => {
_repaymentList(req, res, next, {
title: '近7日待还款',
posId: 2
}, {
... ... @@ -269,8 +272,8 @@ const sevenDayList = (req, res) => {
};
// 本月待还款列表
const monthRepayList = (req, res) => {
_repaymentList(req, res, {
const monthRepayList = (req, res, next) => {
_repaymentList(req, res, next, {
title: '本月待还金额',
posId: 3
}, {
... ... @@ -279,8 +282,8 @@ const monthRepayList = (req, res) => {
};
// 待还总金额列表
const totalRepayList = (req, res) => {
_repaymentList(req, res, {
const totalRepayList = (req, res, next) => {
_repaymentList(req, res, next, {
title: '待还总金额',
posId: 4
}, {
... ... @@ -300,7 +303,7 @@ const repayRecordPage = (req, res) => {
};
// ajax 请求还款记录
const getRepayRecord = (req, res) => {
const getRepayRecord = (req, res, next) => {
let params = _.assign({
uid: req.user.uid,
pageNo: req.query.page || 1
... ... @@ -315,11 +318,11 @@ const getRepayRecord = (req, res) => {
} else {
res.json();
}
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '还款记录'
});
}, err, next);
});
};
... ... @@ -365,18 +368,18 @@ const bindCard = (req, res) => {
};
// 添加新银行卡请求
const postAccount = (req, res) => {
const postAccount = (req, res, next) => {
var params = _.assign({
uid: req.user.uid
}, req.query);
installmentModel.postAccount(params).then((result) => {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '使用新卡还款'
});
}, err, next);
});
};
... ... @@ -407,7 +410,7 @@ function getRealIP(req) {
return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress;
}
const activateService = (req, res) => {
const activateService = (req, res, next) => {
installmentModel.activateService({
uid: req.user.uid,
... ... @@ -423,34 +426,34 @@ const activateService = (req, res) => {
ip: getRealIP(req)
}).then((result)=> {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '开通有货分期'
});
}, err, next);
});
};
const getBankInfo = (req, res) => {
const getBankInfo = (req, res, next) => {
installmentModel.getBankInfo({
cardNo: req.query.cardNo,
uid: req.user.uid
}).then((result)=> {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
const verifyCode = (req, res) => {
const verifyCode = (req, res, next) => {
installmentModel.sendVerifyCode(req.user.uid || 1, req.query.mobile).then((result)=> {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
... ... @@ -465,7 +468,7 @@ const orderIndex = (req, res) => {
});
};
const orderList = (req, res) => {
const orderList = (req, res, next) => {
const params = {
uid: req.user.uid,
type: req.query.type || 1,
... ... @@ -493,15 +496,15 @@ const orderList = (req, res) => {
layout: false,
isInstallmentPage: true
});
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '我的分期订单'
});
}, err, next);
});
};
const orderDetail = (req, res) => {
const orderDetail = (req, res, next) => {
const params = {
uid: req.user.uid,
orderCode: req.params.id
... ... @@ -586,16 +589,16 @@ const orderDetail = (req, res) => {
}
}
});
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '分期详情'
});
}, err, next);
});
};
// 还款详情
const repayDetail = (req, res) => {
const repayDetail = (req, res, next) => {
let params = {
uid: req.user.uid,
rePayNo: req.query.id || '',
... ... @@ -608,11 +611,11 @@ const repayDetail = (req, res) => {
isInstallmentPage: true,
isOne: true
}, result[0]));
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '还款详情'
});
}, err, next);
});
};
... ... @@ -631,24 +634,24 @@ const agreement = (req, res) => {
};
// 计算金额
const totalAmount = (req, res) => {
const totalAmount = (req, res, next) => {
installmentModel.totalAmount(req.query.prices).then((result) => {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
// 检查验证码
const checkVerifyCode = (req, res) => {
const checkVerifyCode = (req, res, next) => {
installmentModel.checkVerifyCode(req.user.uid, req.query.mobile, req.query.code).then((result) => {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl
});
}, err, next);
});
};
... ... @@ -658,7 +661,7 @@ const serverCrash = (req, res) => {
};
// 银行卡列表
const bankCard = (req, res) => {
const bankCard = (req, res, next) => {
let uid = req.user.uid;
installmentModel.getBankCards(uid).then((result) => {
... ... @@ -668,18 +671,18 @@ const bankCard = (req, res) => {
title: '我的银行卡',
isInstallmentPage: true,
accountList: result,
userName: result[0].userName
userName: _.get(result, '[0].userName')
});
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '我的银行卡'
});
}, err, next);
});
};
// 银行卡详情
const cardDetail = (req, res) => {
const cardDetail = (req, res, next) => {
let uid = req.user.uid;
let cardIdNo = req.query.cardIdNo;
... ... @@ -692,16 +695,16 @@ const cardDetail = (req, res) => {
width750: true,
cardDetail: result
});
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '银行卡详情'
});
}, err, next);
});
};
// 删除绑定
const delBankCard = (req, res) => {
const delBankCard = (req, res, next) => {
let params = {
uid: req.user.uid,
cardIdNo: req.query.cardIdNo
... ... @@ -709,16 +712,16 @@ const delBankCard = (req, res) => {
installmentModel.delBankCard(params).then((result) => {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '银行卡详情'
});
}, err, next);
});
};
// 切换银行卡绑定
const setMasterCard = (req, res) => {
const setMasterCard = (req, res, next) => {
let params = {
uid: req.user.uid,
cardIdNo: req.query.cardIdNo
... ... @@ -726,27 +729,15 @@ const setMasterCard = (req, res) => {
installmentModel.setMasterCard(params).then((result) => {
res.json(result);
}).catch(() => {
}).catch((err) => {
_serverCrash(res, {
url: req.originalUrl,
title: '银行卡详情'
});
}, err, next);
});
};
const sessionKeyAuth = (req, res, next) => {
let uid = req.query.uid || req.cookies.installmentUid || (req.user.uid && req.user.uid.toString()) || '';
let sessionKey = _.get(req, 'user.uid.sessionKey');
if (sessionKey && !req.session.SESSION_KEY) {
req.session.SESSION_KEY = uid.sessionKey;
}
req.user.uid = {
toString: () => {
return uid.toString();
},
sessionKey
};
next();
};
... ...
... ... @@ -19,25 +19,6 @@ const codeContent = {
advertisement: 'f3fe0793a7d59479542a14b15359c47d'
};
/**
* 处理旧版本的app兼容新接口
* @param {*} url url
* @param {*} data data
* @param {*} param param
* @param {*} method method
*/
const middleApi = (url, data, param, method) => {
try {
let promise = method === 'post' ? api.post : api.get;
if (!_.get(data, 'uid.sessionKey', '') && data.uid) {
data.app_version = '5.5.0';
}
return promise.call(api, url, data, param);
} catch (err) {
return null;
}
};
// 处理还款列表数据
const _processAmtList = (listData, queryDays) => {
... ... @@ -217,7 +198,7 @@ const _DEBUG = false;// true;
// 获取分期开通状态
const getStauts = (uid) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.getStatus',
uid: uid
}, {
... ... @@ -234,7 +215,7 @@ const getStauts = (uid) => {
// 获取用户可用额度信息
const getQueryCreditInfo = (uid) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.queryCreditLimit',
uid: uid
}, {
... ... @@ -251,7 +232,7 @@ const getQueryCreditInfo = (uid) => {
// 获取用户待还款金额
const getQueryAmtInfo = (uid) => {
return middleApi('', {
return api.get('', {
method: 'app.order.queryAmtInfo',
uid: uid
}, {
... ... @@ -270,7 +251,7 @@ const getQueryAmtInfo = (uid) => {
// 获取用户待还列表信息 queryDays -1:逾期待还;0:全部待还;7:七日待还;30:本月待还
const getQueryAmtList = (params) => {
return middleApi('', _.assign({
return api.get('', _.assign({
method: 'app.order.queryAmtList',
pageSize: '20'
}, params), {
... ... @@ -287,14 +268,14 @@ const getQueryAmtList = (params) => {
// 分期专享推荐商品
const getSearchIntallment = (params) => {
return middleApi('', {
return api.post('', {
method: 'app.search.instalment',
limit: '50',
page: params.page
}, {
cache: true,
timeout: API_TIMEOUT
}, 'post').then((result) => {
}).then((result) => {
if (result && result.code === 200) {
let goods = productProcess.processProductList(result.data.product_list);
... ... @@ -319,7 +300,7 @@ const getSearchIntallment = (params) => {
* @param mobile 手机号码
*/
const sendVerifyCode = (uid, mobile) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.getSnsCheckCode',
uid: uid,
mobile: mobile,
... ... @@ -342,7 +323,7 @@ const sendVerifyCode = (uid, mobile) => {
* @returns {*}
*/
const activateService = (params) => {
return middleApi('', Object.assign({
return api.get('', Object.assign({
method: 'user.instalment.activate'
}, params), {
timeout: 30000
... ... @@ -357,7 +338,7 @@ const activateService = (params) => {
* @returns {*}
*/
const getBankInfo = (params) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.getBankInfoByCardNo',
cardNo: params.cardNo,
uid: params.uid
... ... @@ -380,7 +361,7 @@ const getInstallmentOrders = (params) => {
const method = 'app.SpaceOrders.getInstallment';
if (!_DEBUG) {
return middleApi('', {
return api.get('', {
method: method,
uid: params.uid,
type: params.type || 1,
... ... @@ -398,7 +379,7 @@ const getInstallmentOrders = (params) => {
// 还款记录查询
const getQueryRePayList = (params) => {
return middleApi('', _.assign({
return api.get('', _.assign({
method: 'app.order.queryRePayList',
pageSize: '20'
}, params), {
... ... @@ -415,7 +396,7 @@ const getQueryRePayList = (params) => {
// 账号管理
const getBankCards = (uid) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.getBankCards',
uid: uid
}, {
... ... @@ -441,7 +422,7 @@ const getBankCards = (uid) => {
const getInstallmentOrderDetail = (params) => {
const method = 'app.SpaceOrders.installDetail';
return middleApi('', {
return api.get('', {
method: method,
uid: params.uid,
order_code: params.orderCode
... ... @@ -462,7 +443,7 @@ const getInstallmentOrderDetail = (params) => {
const totalAmount = (params) => {
const method = 'app.order.calPrice';
return middleApi('', {
return api.get('', {
method: method,
prices: params
}, {
... ... @@ -476,7 +457,7 @@ const totalAmount = (params) => {
const checkVerifyCode = (uid, mobile, code) => {
const method = 'user.instalment.validateSnsCheckCode';
return middleApi('', {
return api.get('', {
uid: uid,
method: method,
mobile: mobile,
... ... @@ -491,7 +472,7 @@ const checkVerifyCode = (uid, mobile, code) => {
// 添加银行卡请求
const postAccount = (params) => {
return middleApi('', _.assign({
return api.get('', _.assign({
method: 'user.instalment.bindingCards'
}, params), {
timeout: 6000
... ... @@ -500,7 +481,7 @@ const postAccount = (params) => {
// 获取银行卡详情
const getCardDetail = (uid, cardIdNo) => {
return middleApi('', {
return api.get('', {
method: 'user.instalment.getBankCardDetail',
uid: uid,
cardIdNo: cardIdNo
... ... @@ -518,7 +499,7 @@ const getCardDetail = (uid, cardIdNo) => {
// 解除银行卡绑定
const delBankCard = (params) => {
return middleApi('', _.assign({
return api.get('', _.assign({
method: 'user.instalment.unbindCard'
}, params)).then((res) => {
return res;
... ... @@ -527,7 +508,7 @@ const delBankCard = (params) => {
// 切换银行卡主卡
const setMasterCard = (params) => {
return middleApi('', _.assign({
return api.get('', _.assign({
method: 'user.instalment.toggleCard'
}, params)).then((res) => {
return res;
... ... @@ -536,7 +517,7 @@ const setMasterCard = (params) => {
// 公告
const getNotices = () => {
return middleApi('', {
return api.get('', {
method: 'app.resources.getNotices',
position: 8,
client_type: 'iphone'
... ...
... ... @@ -76,7 +76,13 @@ const common = {
refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), {
domain: 'yohobuy.com'
});
if (req.yoho.isApp) {
return next({
code: 401,
message: 'weblogin',
refer
});
}
next();
},
weixinCheck: (req, res, next) => {
... ...
... ... @@ -153,5 +153,4 @@ let captcha = require('./controllers/captcha');
router.get('/passport/captcha/get', captcha.get);
router.get('/passport/img-check.jpg', captcha.imgCheck);
module.exports = router;
... ...
... ... @@ -10,7 +10,6 @@ exports.appAdapter = (req, res, next) => {
if (req.yoho.isApp && !req.user.uid) {
req.user.uid = req.query.uid;
}
next();
};
... ...
... ... @@ -15,11 +15,16 @@ module.exports = (req, res, next) => {
message: '抱歉,您暂未登录!',
redirect: '/passport/login'
});
} else if (req.yoho.isApp) {
return next({
code: 401,
message: 'weblogin'
});
} else {
return res.redirect(helpers.urlFormat('/signin.html', {
refer: req.originalUrl
}));
}
return res.redirect(helpers.urlFormat('/signin.html', {
refer: req.originalUrl
}));
}
next();
... ...
... ... @@ -52,7 +52,23 @@ exports.serverError = () => {
if (err && err.code === 401) {
if (req.xhr) {
return res.json(err);
return res.status(401).json(err);
} else if (req.yoho.isApp) {
if (err.lowVersion) {
return res.render('error/app-auth', {
module: 'common',
page: 'app-update',
localCss: true,
message: err.message
});
}
return res.render('error/app-auth', {
module: 'common',
page: 'app-redirect-login',
message: '验证失败,请登录',
localCss: true,
refer: err.refer
});
} else {
return res.redirect(helpers.urlFormat('/signin.html', {
refer: req.originalUrl
... ...
... ... @@ -48,7 +48,7 @@ module.exports = () => {
yoho.channel = channel;
// 判断请求是否来自app
yoho.isApp = req.query.app_version || req.query.appVersion;
yoho.isApp = req.query.app_version || req.query.appVersion || req.cookies.app_version;
yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');
yoho.isWeibo = ua.indexOf('weibo') !== -1;
yoho.isqq = /MQQBrowser/i.test(req.get('User-Agent') || '');
... ...
... ... @@ -33,42 +33,22 @@ module.exports = () => {
};
}
if (!req.user.uid && req.cookies.app_uid && req.cookies.app_session_key) {
if (!req.user.uid &&
req.cookies.app_uid &&
req.cookies.app_uid !== '0' &&
req.cookies.app_session_key &&
req.cookies.app_version &&
req.cookies.app_client_type) {
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return req.cookies.app_uid;
return _.parseInt(req.cookies.app_uid);
},
sessionKey: req.cookies.app_session_key,
appVersion: req.cookies.app_version || void 0,
appSessionType: req.cookies.app_client_type || void 0
appVersion: req.cookies.app_version,
appSessionType: req.cookies.app_client_type
};
}
if (!req.user.uid &&
(req.query.uid || req.cookies.app_uid) &&
(req.query.client_type || req.cookies.app_client_type) &&
(req.query.app_version || req.cookies.app_version)) {
let uid = req.query.uid || req.cookies.app_uid;
req.query.uid = {
toString: () => {
return uid;
},
appVersion: req.query.app_version || req.cookies.app_version || void 0,
appSessionType: req.query.client_type || req.cookies.app_client_type || void 0
};
res.cookie('app_uid', req.query.uid.toString(), {
domain: 'm.yohobuy.com'
});
res.cookie('app_client_type', req.query.uid.appSessionType, {
domain: 'm.yohobuy.com'
});
res.cookie('app_version', req.query.uid.appVersion, {
domain: 'm.yohobuy.com'
});
}
next();
};
};
... ...
<div class="tip">{{message}}</div>
<a href="#" id="yoho-app-link"></a>
<input type="hidden" id="no-download" value="1" />
{{#if refer}}
<input type="hidden" id="refer" value="{{refer}}" />
{{/if}}
\ No newline at end of file
... ...
... ... @@ -50,7 +50,7 @@
"xml2js": "^0.4.17",
"yoho-express-session": "^2.0.0",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "=0.2.17",
"yoho-node-lib": "=0.2.18",
"yoho-zookeeper": "^1.0.8"
},
"devDependencies": {
... ...
... ... @@ -66,7 +66,7 @@ const cssLoader = (env, type) => {
const getEntries = () => {
const entries = {
libs: ['babel-polyfill', 'yoho-jquery'],
libs: ['babel-polyfill', 'yoho-jquery', path.join(__dirname, '../js/global.js')],
index: path.join(__dirname, '../scss/index.css'),
common: path.join(__dirname, '../scss/common.css'),
feature: path.join(__dirname, '../scss/feature.css')
... ...
((function() {
require('common/_app-auth.css');
let yohoApp = require('../yoho-app'),
$ = require('yoho-jquery'),
cookie = require('yoho-cookie');
let $refer = $('#refer');
let href = location.href;
if ($refer.length) {
href = $refer.val();
if (href.indexOf(location.host) < 0) {
href = `${location.protocol}//${location.host}${href}`;
}
}
let oldSessionKey = localStorage.getItem('oldSessionKey') || '';
let oldSessionKeyErr = parseInt(localStorage.getItem('oldSessionKeyErr') || -1, 10);
let sessionKey = cookie.get('app_session_key');
if (!sessionKey) {
return;
}
if (oldSessionKey === sessionKey) {
if (oldSessionKeyErr < 3) {
localStorage.setItem('oldSessionKeyErr', oldSessionKeyErr + 1);
} else {
localStorage.removeItem('oldSessionKeyErr');
return;
}
}
localStorage.setItem('oldSessionKey', sessionKey);
yohoApp.goLogin(href);
})());
... ...
require('common/_app-auth.css');
... ...
... ... @@ -5,19 +5,25 @@
*/
const $ = require('yoho-jquery');
const cookie = require('yoho-cookie');
let yoho = require('./yoho-app');
const tip = require('plugin/tip');
const yoho = require('./yoho-app');
// 初始化
// 注册ajaxError处理服务端401状态
$(document).ajaxError((event, xhr) => {
if (xhr.status === 401) {
cookie.remove('_UID');
cookie.remove('_TOKEN');
if (yoho.isApp) {
yoho.goLogin(window.location.href);
if (xhr.responseJSON && xhr.responseJSON.lowVersion) {
tip.show(xhr.responseJSON.message);
} else {
window.location.href = `/signin.html?refer=${encodeURIComponent(window.location.href)}`;
cookie.remove('_UID');
cookie.remove('_TOKEN');
if (yoho.isApp) {
yoho.goLogin(window.location.href);
} else {
window.location.href = `/signin.html?refer=${encodeURIComponent(window.location.href)}`;
}
}
}
});
... ...
... ... @@ -14,6 +14,8 @@ let $ = require('yoho-jquery');
let tip = require('./plugin/tip');
let cookie = require('yoho-cookie');
require('common');
/* 空方法 */
let emptyFn = function() {};
... ... @@ -35,7 +37,7 @@ yoho = {
/**
* 判断是否是 APP
*/
isApp: /YohoBuy/i.test(navigator.userAgent || '') || qs && qs.app_version,
isApp: /YohoBuy/i.test(navigator.userAgent || '') || qs && qs.app_version || cookie.get('app_version'),
isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''),
isAndroid: /Android/i.test(navigator.userAgent || ''),
... ... @@ -130,20 +132,35 @@ yoho = {
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
refer = yoho.parseUrl(refer || location.href);
if (this.isApp) {
url = location.href;
if (this.isAndroid) {
if (url.indexOf('?') < 0) {
url += '?appLogin=1';
}
if (location.href.indexOf('&openby') >= 0) {
url = url.substring(0, url.indexOf('&openby'));
}
url += '&';
} else {
if (location.href.indexOf('#openby') >= 0) {
url = url.substring(0, url.indexOf('#openby'));
}
url += '#';
}
if (yoho.isApp) {
url = url + '&openby:yohobuy=' + (data || JSON.stringify({
url += 'openby:yohobuy=' + (data || JSON.stringify({
action: 'go.weblogin',
params: {
priority: 'N',
jumpurl: {
url: refer.path,
param: refer.query
}
},
needlogout: 'Y'
}
}));
}
$appLink.attr('href', url);
$appLink[0].click();
return false;
... ...
.tip {
text-align: center;
margin-top: 100px;
font-size: 32px;
}
... ...