The applet determines whether it is authorized

/**

* Determine whether there is permission to obtain user information

*/

isAuthUserInfo: function () {

var that = this;

// You can first query whether the user has authorized the scope "scope.userInfo" through wx.getSetting

 

wx.getSetting({

success(res) {

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

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

wx.authorize({

scope: 'scope.userInfo',

success() {

// The user has agreed to the applet to obtain user information

wx.getUserInfo();

 

that.getUserInfo();


 

res.authSetting = {

"scope.userInfo": true,

"scope.userLocation": true

}

},

fail() {

wx.showModal({

title: 'Please authorize',

content: 'User authorization is required to log in',

success: function (res) {

if (res.confirm) {

console.log('User clicks OK')

wx.openSetting({

success: (res) => {

 

res.authSetting = {

"scope.userInfo": true,

"scope.userLocation": true

}

 

},

fail() {

wx.showModal({

title: 'Please set',

content: 'Please set',

})

that.isAuthUserInfo();

}

})

} else if (res.cancel) {

that.isAuthUserInfo();

}

}

})

}

})

 

}

}

})

},

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325330173&siteId=291194637