使用uni-app 的微信登录功能,在回调函数里面 设置了 key
uni.login({
provider: 'weixin',
success: function(loginRes) {
// 获取用户信息
uni.getUserInfo({
provider: 'weixin',
success: async function(infoRes) {
let userInfo = infoRes.userInfo;
//获取 client_id 传递给服务器
//调用接口 获取用户信息
let client_id = uni.getStorageSync('client_id');
userInfo.client_id = client_id;
let res = await api.wx_login(userInfo);
if (res.code != 200) {
//提示错误信息
uni.showModal({
title: '错误',
content: res.datas.error,
showCancel: false,
success: function() {
},
});
return false;
}
**uni.setStorageSync('key', res.datas.token);**
**uni.setStorageSync('mp_key', res.datas.mp_token);**
uni.redirectTo({
url: "/pages/index/index"
})
}
});
},
fail: function(e) {
console.log(e, '+++++')
}
});
然后在程序的 APP.VUE 页面 onLaunch 钩子里面 检测登录状态
checkLogin: function() {
let key = uni.getStorageSync('key')
if (!key) {
uni.showToast({
title:'请先登录!',
icon:'none',
success:function(){
uni.redirectTo({
url:'/pages/login/login'
})
}
});
}
},
每次后台关闭APP 后再次打开就会提示登录
请问这可能是哪里的问题?
1 个回复
2***@qq.com
大佬解决了吗