微信登录授权详细流程,供新手参考,大神绕路

个人开发,微信小游戏 登录授权流程,判断是否授权,拒绝授权处理

wx.login({
  success: (function (res) {
    this.wxCode = res.code
    this.wxGetUserState()
  }.bind(this)
  )
})

wxGetUserState: function () {
    wx.getSetting({
        fail: function (res) {
            this.wxGetUserInfo()
        }.bind(this),

        success: function (res) {
            if (res.authSetting['scope.userInfo']) {
                this.getUserInfo()
            }
            else{
                this.wxGetUserInfo()
            }
        }.bind(this)
        })
},

wxGetUserInfo: function () {
    this.WXInfoButton = wx.createUserInfoButton(
        type: 'text',
        text: '',
        style: {
            left: 0,
            top: 0,
            width: this.windowWidth,
            height: this.windowHeight,
            lineHeight: 600,
            backgroundColor: '#FFFFFF00',
            borderColor: '#FFFFFF',
            color: '#FFFFFF',
            textAlign: 'center',
            fontSize: 40,
            borderRadius: 4
        }
    })
    this.WXInfoButton.onTap((res) => {
        if (res.errMsg.indexOf('auth deny') > -1 || res.errMsg.indexOf('auth denied') > -1) {
            // 处理用户拒绝授权的情况
            this.guideActive()
        }else {
            this.setUserData(res)
        }
    })
    this.WXInfoButton.show()

},

getUserInfo() {
    wx.getUserInfo({
        fail: function (res) {
            if (res.errMsg.indexOf('auth deny') > -1 || res.errMsg.indexOf('auth denied') > -1) {
                // 处理用户拒绝授权的情况
                this.guideActive()
            }
        }.bind(this),
        success: function (res) {
            this.setUserData(res)
        }.bind(this)
    })
},

guideActive: function () {
    wx.showModal({
    title: '警告',
    content: '拒绝授权将无法正常游戏',
    cancelText: '取消',
    showCancel: true,
    confirmText: '设置',
    success: (function (res) {
        if (res.confirm) {
        wx.openSetting({
            success: (function (res) {
            if (res.authSetting['scope.userInfo'] === true) {
                this.getUserInfo()
            }
            }).bind(this)
        })
        }else {
        }
    }).bind(this)
    })
},


setUserData: function (res) {
    this.userInfo =  res.userInfo
    this.signature = res.signature
    this.encryptedData = res.encryptedData
    this.rawData = res.rawData
    this.iv = res.iv
},
13赞

愿意分享的人都是好人

判断是否授权,拒绝授权处理,获得数据

个人学习,一起交流下

附带个人小游戏,里面有什么功能需要的,可以一起分享交流

谢谢分享!!!
马克!!!

黑屏。。。

什么手机型号啊

mark

点赞 点赞

mark

mark

赞一个!

视频播放次数用完之后建议免费使用弃牌:joy::joy:

有个问题没做低版本兼容你的这个登陆

createUserInfoButton这个方法只有微信2.0.1版本以上能调用以下的会报错

直接设置2.2.0以上才允许游戏?

你这个图怎么生成的啊

楼主就是大神