个人开发,微信小游戏 登录授权流程,判断是否授权,拒绝授权处理
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
},

