微信小程序两种重新获取授权的解决方法

第一种:

在onLoad里面直接获取授权,拒绝时跳出弹框,提醒用户是否确定拒绝,如果点击获取授权,则调出微信自身的系统页面,获取个人信息,

wx.login({
success: function (res) {
var JSCODE = res.code
wx.getUserInfo({
lang: 'zh_CN',
success: function (res) {
console.log(res);
var userInfo = res.userInfo;
var cardNikeName = userInfo.nickName;
var avatarUrl = userInfo.avatarUrl;
var area = userInfo.province;
var encryptedData = res.encryptedData;
var iv = res.iv;
app.globalData.userInfo = res.userInfo;
wx.setStorageSync( "userInfo", res.userInfo)
var value = wx.getStorageSync( 'channel')
console.log(value)
wx.request({
url: 'https://laohuangli.intbull.com/little/little.jsp',
data: {
cmd: 'login',
channel: value,
app_id: "wxd1949f3130a58e73",
code: JSCODE,
encrypted_data: encryptedData,
iv: iv,
},
header: {
'content-type': 'application/json'
},
success: function (res) {
app.globalData.open_id = res.data.open_id;
console.log(res.data.open_id)
wx.setStorageSync( "open_id", res.data.open_id)
}
})
},
fail: function () {
wx.showModal({
title: '警告',
content: '您点击了拒绝授权,将无法正常显示个人信息,点击确定重新获取授权。',
success: function (res) {
if (res.confirm) {
wx.openSetting({
success: (res) => {
if (res.authSetting[ "scope.userInfo"]) { ////如果用户重新同意了授权登录
wx.getUserInfo({
success: function (res) {
var userInfo = res.userInfo;
that.setData({
nickName: userInfo.nickName,
avatarUrl: userInfo.avatarUrl,
})
}
})
}
}
})
}
}
})
}
})
}
})

第二种:

跳出弹框被拒绝,做一个按钮,点击还能跳出弹框

wx.getUserInfo({
success: function (res) {
console.log(res)
},
fail: function () {
}

})
在点击函数中调用,就可重复出现弹框

你可能感兴趣的:(微信小程序两种重新获取授权的解决方法)