收藏
回答

如何解决微信小程序登录,服务端解密有几率报错-41003的问题?

我搜索过社区中,查看了其他很多人的解决方案,一直没有找到解决方法,我是用户信息和手机号一起获取,是这个方向不能实现吗?

前台代码:

授权登陆


js代码:

login: function (res{
    var that=this;
    wx.login({
      successfunction (e{
        var code = encodeURIComponent(e.code);
        wx.getUserInfo({
          lang"zh_CN",
          successfunction (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",
              successfunction (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错误

最后一次编辑于  2020-12-18
回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签