作者 wumengyu

优化登录出现参数错误问题

... ... @@ -116,7 +116,7 @@ Page({
};
app.post(url, params, header).then((res) => {
// console.log('打卡结果', res);
if (res.is_success) {
if (+res.is_success) {
this.setData({
punchState: false,
'state_data.is_showSuccessModal': true,
... ...
... ... @@ -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;
... ...