...
|
...
|
@@ -13,36 +13,45 @@ Page({ |
|
|
// 获取用户信息
|
|
|
start(e) {
|
|
|
let self = this;
|
|
|
wx.checkSession({
|
|
|
success: function () {
|
|
|
console.log('未过期');
|
|
|
//session_key 未过期,并且在本生命周期一直有效
|
|
|
let url = '/wxapp/public/login';
|
|
|
let params = {
|
|
|
encrypted_data: e.detail.encryptedData,
|
|
|
iv: e.detail.iv,
|
|
|
raw_data: e.detail.rawData,
|
|
|
signature: e.detail.signature,
|
|
|
openid: self.data.openid,
|
|
|
session_key: self.data.session_key,
|
|
|
};
|
|
|
app.post(url, params).then((ret) => {
|
|
|
wx.setStorageSync('token', ret.token);
|
|
|
app.globalData.userInfo = ret.user_type;
|
|
|
if (wx.getStorageSync('token') !== '') {
|
|
|
self.checkMobile();
|
|
|
|
|
|
|
|
|
}
|
|
|
// console.log('userInfo',app.globalData.userInfo,ret);
|
|
|
})
|
|
|
},
|
|
|
fail: function () {
|
|
|
console.log('session_key 已经失效');
|
|
|
// session_key 已经失效,需要重新执行登录流程
|
|
|
self.login() //重新登录
|
|
|
}
|
|
|
})
|
|
|
// console.log(self.data.openid === '', self.data.session_key === '');
|
|
|
if(self.data.openid === '' || self.data.session_key === '') {
|
|
|
wx.showLoading({title: '请稍候', mask: true});
|
|
|
self.login();
|
|
|
setTimeout(function () {
|
|
|
wx.hideLoading()
|
|
|
}, 1000);
|
|
|
}else {
|
|
|
wx.checkSession({
|
|
|
success: function () {
|
|
|
console.log('未过期');
|
|
|
//session_key 未过期,并且在本生命周期一直有效
|
|
|
let url = '/wxapp/public/login';
|
|
|
let params = {
|
|
|
encrypted_data: e.detail.encryptedData,
|
|
|
iv: e.detail.iv,
|
|
|
raw_data: e.detail.rawData,
|
|
|
signature: e.detail.signature,
|
|
|
openid: self.data.openid,
|
|
|
session_key: self.data.session_key,
|
|
|
};
|
|
|
app.post(url, params).then((ret) => {
|
|
|
wx.setStorageSync('token', ret.token);
|
|
|
app.globalData.userInfo = ret.user_type;
|
|
|
if (wx.getStorageSync('token') !== '') {
|
|
|
self.checkMobile();
|
|
|
|
|
|
|
|
|
}
|
|
|
// console.log('userInfo',app.globalData.userInfo,ret);
|
|
|
})
|
|
|
},
|
|
|
fail: function () {
|
|
|
console.log('session_key 已经失效');
|
|
|
// session_key 已经失效,需要重新执行登录流程
|
|
|
self.login() //重新登录
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
login() {
|
|
|
let self = this;
|
...
|
...
|
|