官方文档地址:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html
之前使用Promise.al(),将wx.login(),wx.getUserProfile(),wx.getUserInfo()但是由于不能保证先调用wx.login(),所以还是会存在校验签名或解密失败问题,为了保证wx.login()方法先执行,进行了以下操作
// 一键授权登录
let loginResult;
let wxLogin = wx.login();
wxLogin.then((result) => {
loginResult = result;
});
let userProfile = await wxGetUserProfile({
desc: "用于设备绑定",
});
let userInfo = await wxGetUserInfo();
if (loginResult == null || loginResult.errMsg !== "login:ok") {
showToast("登录超时,请重新授权", "none", 3000);
return;
}
if (
loginResult.errMsg === "login:ok" &&
userProfile.errMsg == "getUserProfile:ok" &&
userInfo.errMsg == "getUserInfo:ok"
) {
//相关逻辑处理
}