收藏
回答

关于切换账号第一次解密失败

希望得到帮助。

场景,本地微信授权获取用户头像信息,真机同个微信账号授权第一次会解密失败,需要第二次再code

是不是哪里业务错了还是

,希望得到帮助

//绑定微信
bindGetUserInfo: function (e,callback) {
    var that=this;
     
    var id=wx.getStorageSync('id')
    var loginsalt=wx.getStorageSync('loginsalt')
    if(!id || !loginsalt){
        /*wx.reLaunch({
          url: '/pages/login/login'
        })
        return;*/
    }
    if (typeof callback !== 'function') {
        callback = function callback() {};
    }
    if (e.detail.userInfo) {
        wx.showLoading({
            title: '加载中',
            mask:true
        })
        wx.login({
            success: function success(data) {
                wx.getSetting({
                  success: res => {
                    if (res.authSetting['scope.userInfo']) {                                        
                          wx.getUserInfo({
                            success: function success(res) {
                                wx.request({
                                  url: that.data.url+'wechat/wxapp_userinfo',
                                  data: {
                                        id:id,
                                        loginsalt:loginsalt,
                                        code: data.code,
                                        encryptedData: res.encryptedData,
                                        iv: res.iv
                                  },
                                  success(res) {
                                    //解密失败 -41003
                                    //工具微信授权用户信息后,真机再同个微信授权用户信息第一次就解密失败
                                     
                                      wx.hideLoading();
                                      if(res.data.ret==1){
                                            callback(res.data);
                                      }else{
                                            wx.showToast({
                                                title: res.data.msg,
                                                icon: 'none',
                                                duration: 3000
                                            })
                                      }
                                  },fail(){
                                    wx.hideLoading();
                                    wx.showToast({
                                      title: '网络异常',
                                      icon: 'none',
                                      duration: 3000
                                    })
                                  }
                                })
                            }
                        });
                    }else{
                        //wx.redirectTo({ url: '/pages/users/getuinfo/getuinfo' });
                    }
                  }
                })
                 
            }
        });
    }
}


最后一次编辑于  2019-05-09
回答关注问题邀请回答
收藏

5 个回答

  • 西赛德李
    西赛德李
    2019-05-09

    你倒是把代码发上来,我们才能帮你看哪里错了啊

    2019-05-09
    有用 1
    回复 1
    • 
      
      2019-05-09

      感谢,我贴上面了代码你帮我看看啊,谢谢

      2019-05-09
      回复
  • 寻界
    寻界
    2019-05-10

    http://es6.ruanyifeng.com/#docs/promise

    推荐你看下promise的语法,学习下es6,callback的写法不利于阅读

    2019-05-10
    有用
    回复 1
    • 
      
      2019-05-10

      好的,谢谢。

      2019-05-10
      回复
  • 烧饼
    烧饼
    2019-05-10

    看了下,整体业务流水没错误。先login拿到code,再获取用户信息的encryptedData和iv,同时发到后台。后台先解密code,然后在换取session成功后再去解密用户信息。这么紧凑的时序我没试过,可以测试下加个延时,看看是不是微信那边没刷新

    2019-05-10
    有用
    回复 1
    • 
      
      2019-05-10

      好的,谢谢。

      2019-05-10
      回复
  • ZiraLi
    ZiraLi
    2019-05-08


    你好,你可以参照这个逻辑进行获取,相关接口说明已经在文档中很详细了。我没有遇到过楼主的错误,但我用这个不会报错。如果还是有错误可能时逻辑的原因了,可以考虑一下异步造成的错误

    2019-05-08
    有用
    回复 1
    • 
      
      2019-05-08

      嗯嗯

      2019-05-08
      回复
  • 
    
    2019-05-06

    希望得到帮助

    2019-05-06
    有用
    回复 6
    查看更多(1)
登录 后发表内容