小程序判斷是否受權

/**小程序

* 判斷是否有獲取用戶信息的權限this

*/get

isAuthUserInfo: function () {it

var that = this;io

// 能夠經過 wx.getSetting 先查詢一下用戶是否受權了 "scope.userInfo" 這個 scopeconsole

 

wx.getSetting({function

success(res) {登錄

console.log(res.authSetting['scope.userInfo'])權限

if (!res.authSetting['scope.userInfo']) {程序

wx.authorize({

scope: 'scope.userInfo',

success() {

// 用戶已經贊成小程序獲取用戶信息

wx.getUserInfo();

 

that.getUserInfo();


 

res.authSetting = {

"scope.userInfo": true,

"scope.userLocation": true

}

},

fail() {

wx.showModal({

title: '請受權',

content: '須要用戶受權才能登陸',

success: function (res) {

if (res.confirm) {

console.log('用戶點擊肯定')

wx.openSetting({

success: (res) => {

 

res.authSetting = {

"scope.userInfo": true,

"scope.userLocation": true

}

 

},

fail() {

wx.showModal({

title: '請設置',

content: '請設置',

})

that.isAuthUserInfo();

}

})

} else if (res.cancel) {

that.isAuthUserInfo();

}

}

})

}

})

 

}

}

})

},

相關文章
相關標籤/搜索