旧版本:
Login:function(callback = () =>{}){
let that = this;
uni.login({
success:function(loginRes){
if(loginRes){
uni.getUserInfo({
withCredentials:true,
success:function(infoRes){
util.request({
url: api.loginUrl,
data:{
code:loginRes.code,//临时登录凭证
rawData:infoRes.rawData,//用户非敏感信息
signature:infoRes.signature,//签名
encrypteData:infoRes.encryptedData,//用户敏感信息
iv:infoRes.iv//解密算法的向量
},
success:function(res){
console.log(‘login success’);
res = res.data;
if(res.result0){
that.globalData.userInfo = res.userInfo;
uni.setStorageSync(‘userInfo’,JSON.stringify(res.userInfo));
uni.setStorageSync(‘loginFlag’,res.skey);
console.log(“skey=”+res.skey);
callback();
}else{
that.showInfo(‘res.errmsg’);
}
},
fail:function(error){
// that.showInfo(‘调用接口失败’);
console.log(error);
}
});
}
});
}else{
}
}
});
}
新版本:
Login:function(callback = () =>{}){
let that = this;
uni.login({
success:function(loginRes){
if(loginRes){
uni.getUserProfile({
withCredentials:true,//非必填 默认为true
success:function(infoRes){
uni.request({
url: api.loginUrl,
data:{
code:loginRes.code,//临时登录凭证
rawData:infoRes.rawData,//用户非敏感信息
signature:infoRes.signature,//签名
encrypteData:infoRes.encryptedData,//用户敏感信息
iv:infoRes.iv//解密算法的向量
},
success:function(res){
console.log(‘login success’);
res = res.data;
if(res.result0){
that.globalData.userInfo = res.userInfo;
uni.setStorageSync(‘userInfo’,JSON.stringify(res.userInfo));
uni.setStorageSync(‘loginFlag’,res.skey);
console.log(“skey=”+res.skey);
callback();
}else{
that.showInfo(‘res.errmsg’);
}
},
fail:function(error){
// that.showInfo(‘调用接口失败’);
console.log(error);
}
});
}
});
}else{
}
}
});
}
2021.4月28日24时新版本微信小程序登录授权新方法
最新推荐文章于 2023-03-23 18:12:27 发布