微信小程序----用户拒绝授权,重新调起授权

获取用户信息
wx.getUserInfo({
withCredentials: true,
success: function (res) {
var nickName = res.userInfo.nickName;
var avatarUrl = res.userInfo.avatarUrl;
var gender = res.userInfo.gender;
wx.login({
success: function (res) {
if (res.code) {
var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
wx.request({
url: _this.globalData.domain + "Index/login",
data: {
encrypt_data: rsaData
},
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
const user_id = res.data.data.user_id;
var openid = res.data.data.openid;
wx.setStorage({
key: 'user_id',
data: user_id,
})
wx.setStorage({
key: 'openid',
data: openid,
})
// 获取会员信息
var rsaData = _this.rsaData({ user_id: user_id })
wx.request({
url: _this.globalData.domain + "user/get_user",
data: {
encrypt_data: rsaData,
token: wx.getStorageSync('token')
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: "POST",
success: function (res) {

},
})
},
})
}
}
})
},
fail: function (res) {
var that = this;
wx.openSetting({
success(res) {
if (!res.authSetting['scope.userInfo'] || !res.authSetting["scope.userLocation"]) {
wx.authorize({
scope: 'scope.userInfo',
success(res) {
// 失败之后再次登入
wx.getUserInfo({
withCredentials: true,
success: function (res) {
var nickName = res.userInfo.nickName;
var avatarUrl = res.userInfo.avatarUrl;
var gender = res.userInfo.gender;
wx.login({
success: function (res) {
if (res.code) {
var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
wx.request({
url: _this.globalData.domain + "Index/login",
data: {
encrypt_data: rsaData
},
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
const user_id = res.data.data.user_id;
var openid = res.data.data.openid;
wx.setStorage({
key: 'user_id',
data: user_id,
})
wx.setStorage({
key: 'openid',
data: openid,
})
// 获取会员信息
var rsaData = _this.rsaData({ user_id: user_id })
wx.request({
url: _this.globalData.domain + "user/get_user",
data: {
encrypt_data: rsaData,
token: wx.getStorageSync('token')
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: "POST",
success: function (res) {

},
})
},
})
}
}
})
},
})
// 失败之后再次登入
}, fail: (res) => {
/*
* 点击取消之后再次获取user_id 和openid
*/
wx.showModal({
title: '警告',
content: '您点击了拒绝授权,将无法正常使用******的功能体验,请10分钟后再次点击授权,或者删除小程序重新进入',
success: function (res) {
if (res.cancel) {
wx.openSetting({
success: (res) => {
// 失败之后再次登入
wx.getUserInfo({
withCredentials: true,
success: function (res) {
var nickName = res.userInfo.nickName;
var avatarUrl = res.userInfo.avatarUrl;
var gender = res.userInfo.gender;
wx.login({
success: function (res) {
if (res.code) {
var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
wx.request({
url: _this.globalData.domain + "Index/login",
data: {
encrypt_data: rsaData
},
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
const user_id = res.data.data.user_id;
var openid = res.data.data.openid;
wx.setStorage({
key: 'user_id',
data: user_id,
})
wx.setStorage({
key: 'openid',
data: openid,
})
// 获取会员信息
var rsaData = _this.rsaData({ user_id: user_id })
wx.request({
url: _this.globalData.domain + "user/get_user",
data: {
encrypt_data: rsaData,
token: wx.getStorageSync('token')
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: "POST",
success: function (res) {

},
})
},
})
}
}
})
},
})
// 失败之后再次登入
}
})
}
},
})
}
})
}
}
})
}
})

  方法可能有点繁琐,有不足的地方还请多指教

转载于:https://www.cnblogs.com/liujun1128/p/8805271.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值