微信登录问题

在iphonex上,需要清除缓存,然后才能登陆

 getPhoneNumber (e) {
        console.log(e.mp.detail.errMsg)
        console.log(e.mp.detail.iv)
        console.log(e.mp.detail.encryptedData)
        if (e.mp.detail.errMsg === 'getPhoneNumber:fail user deny') {
          wx.showModal({
            title: '提示',
            showCancel: false,
            content: '未授权',
            success (res){}
          })
          return
        }
        // 授权成功
        console.log('success')
        let vm = this
        let encryptedData = e.mp.detail.encryptedData
        let iv = e.mp.detail.iv
        let code = this.$get('url_code')
        if (!code) {
          console.log("ajg");
          wx.login({
            success (res) {
              if (res.code) {
                console.log(res.code)
                vm.$put('url_code', res.code, 250)
                vm.wxMiniProgramLogin(vm, res.code, encryptedData, iv)
                // wx.setStorageSync('url_code', res.code)
              } else {
                console.log('获取用户登录态失败!' + res.errMsg)
              }
            }
          })
        }
        this.wxMiniProgramLogin(vm, code, encryptedData, iv)
      },
      wxMiniProgramLogin (vm, code, encryptedData, iv) {
        wx.request({
          url: `${baseURL}/authentication/login/kyk-news`,
          data: {
            code: code,
            encryptedData: encryptedData,
            iv: iv,
          },
          header: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          method: 'POST',
          success: function (res) {
            // debugger
            // var data = result.data.result;
            // data.expireTime = nowDate + EXPIRETIME;
            // wx.setStorageSync("userInfo", data);
            // userInfo = data

            if (res.data.code !== 200) {
              wx.showToast({
                title: '微信登录失败',
                icon: 'none'
              })
              wx.clearStorageSync()
              return
            }
            let o = res.data['data']
            wx.removeStorageSync('user')
            wx.removeStorageSync('token')
            const { token, userInfoDTO, ...rest } = o
            const user = {
              ...rest,
              ...userInfoDTO
            }
            wx.setStorageSync('user', user)
            wx.setStorageSync('token', token)
            vm.$store.dispatch('pushUser', user)

            setTimeout(function () {
              wx.showToast({
                title: '微信登录成功',
                icon: 'none'
              })
            }, 1000)

            wx.reLaunch({
              url: '/pages/news/index'
            })
            return
          },
          fail () {
            wx.showToast({
              title: '获取手机号失败',
              icon: 'none'
            })
          }
        })
      },

你可能感兴趣的:(微信登录问题)