如何解决微信小程序登录,服务端解密有几率报错-41003的问题?
我搜索过社区中,查看了其他很多人的解决方案,一直没有找到解决方法,我是用户信息和手机号一起获取,是这个方向不能实现吗?
前台代码:
授权登陆
js代码:
login: function (res) {
var that=this;
wx.login({
success: function (e) {
var code = encodeURIComponent(e.code);
wx.getUserInfo({
lang: "zh_CN",
success: function (result) {
var encryptedData= encodeURIComponent(res.detail.encryptedData);
var iv=encodeURIComponent(res.detail.iv);
console.log(res.detail.iv)
wx.request({
url: 'xxxxxxxx',
data: {
code: code,
encryptedData:encryptedData,
iv:iv,
distribution:that.data.distribution
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "post",
success: function (res) {}
})
}
})
}
})
// console.log(res)
},
后台php代码:
$post = $_POST;
$code = urldecode($post['code']);
$encryptedData = urldecode($post['encryptedData']);
$iv = urldecode($post['iv']);
// $phone = $post['phone'];
// $sendCode = $post['sendCode'];
$verifyUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $this->APPID . "&secret=" . $this->secret . "&js_code=" . $code . "&grant_type=authorization_code";
$verify = $this->curl($verifyUrl);
$verify1 = json_decode($verify, true);
$errCode = $this->decryptData($encryptedData, $iv, $verify1['session_key'], $data);
偶尔会出现-41003错误