获取用户信息
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) { },
})
},
})
}
}
})
},
})
// 失败之后再次登入
}
})
}
},
})
}
})
}
}
})
}
})

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

微信小程序----用户拒绝授权,重新调起授权的更多相关文章

  1. 微信小程序-用户拒绝授权使用 wx.openSetting({}) 重新调起授权用户信息

    场景模拟:用户进入微信小程序-程序调出授权 选择拒绝之后,需要用到用户授权才能正常使用的页面,就无法正常使用了. 解决方法:在用户选择拒绝之后,弹窗提示用户 拒绝授权之后无法使用,让用户重新授权(微信 ...

  2. 微信小程序-获取当前城市位置及再次授权地理位置

    微信小程序-获取当前城市位置 1. 获取当前地理位置,可通过wx.getLocation接口,返回经纬度.速度等信息; 注意---它的默认工作机制: 首次进入页面,调用该api,返回用户授权结果,并保 ...

  3. 微信小程序用户数据解密

    概述 通过微信web开发者工具创建登录,获取用户信息,发送至后台,进行用户数据解密 详细 代码下载:http://www.demodashi.com/demo/10705.html 一.准备工作 1. ...

  4. 微信小程序用户信息解密失败导致的内存泄漏问题。

    微信小程序获取用户解密的Session_key 然后对 encryptedData进行解密 偶尔报错 时间长了之后会报内存溢出: java.lang.OutOfMemoryError: GC over ...

  5. 关于微信小程序在ios中无法调起摄像头问题

    这几天关于微信小程序开发关于wx.chooseVideo组件问题,因为自己一直是安卓手机上测试,可以调取摄像头,但是应用在ios上无法打开摄像头,困扰了好多天,经过反复查看官方文档,今天总算修复了这个 ...

  6. 微信小程序 用户登录 服务器端(TP5.1)实现

    先来看官方提供的流程图: 客户端: 小程序客户端通过 wx.login() 获取登录code , 然后将code当做参数传递到服务器. getToken(){ var that = this; wx. ...

  7. 微信小程序没有返回按钮怎么办?微信小程序左上角返回按钮怎么调出来?

    如果你发现自己的小程序页面没有返回按钮,请检查是不是用的wx.redirectTo(OBJECT)进行的跳转,如果是那就把它改成wx.navigateTo(OBJECT)就可以了. wx.naviga ...

  8. 微信小程序 --- 用户登录

    整体逻辑:点击用户中心,如果如果整个页面没有

  9. 微信小程序~用户转发 onShareAppMessage

    只有定义了此事件处理函数,右上角菜单才会显示“转发”按钮,在用户点击转发按钮的时候会调用,此事件需要return一个Object,包含title和path两个字段,用于自定义转发内容 代码使用onSh ...

随机推荐

  1. Dynamics CRM On-Premise V9安装手记

    下载地址: https://download.microsoft.com/download/A/D/D/ADDD6898-4EFA-46FA-80B6-6FE9A3CDED63/CRM9.0-Serv ...

  2. python数据科学 学习之路

    week1 - Python基础1  介绍.基本语法.流程控制 week1- Python基础2   列表.字典.集合 week1- Python基础3   函数.递归.内置函数 week1- Pyt ...

  3. highcharts 大数据 String+,StringBuilder,String.format运行效率比较

    实现String字符串相加的方法有很多,常见的有直接相加,StringBuilder.append和String.format,这三者的运行效率是有差异的,String是final类型的,每次相加都会 ...

  4. Java多线程编程的常见陷阱

    .在构造函数中启动线程 我在很多代码中都看到这样的问题,在构造函数中启动一个线程,类似这样: public class A{ public A(){ ; ; this.thread=new MyThr ...

  5. Servlet+jSP+java实现商品信息和流水的操作

    设计思路:先是创建两个表,一个用来操作库内商品的增删改查,一个用来记录商品的流水信息. 设计过程:先对商品的属性进行创建javaBean编写,之后编写数据库连接类,之后编写数据库操作类,之后编写服务类 ...

  6. poj3984迷宫问题(DFS广搜)

    迷宫问题 Time Limit: 1000MSMemory Limit: 65536K Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, ...

  7. ASP.NET Core开发总结

    1.关于浏览器缓存,修改CSS文件和Javascript文件后调试,浏览器不更新问题,解决办法是在link标签和script标签引用的文件名后面添加版本信息如下: <link rel=" ...

  8. Weblogic漏洞修复记录

    1.CVE-2018-2628.CVE-2018-2893 以上两个漏洞均是针对weblogic的t3服务进行攻击,如果有条件的,可以从oracle官网下载最新的补丁安装http://www.orac ...

  9. unity 根据平板 或者 手机 确立横竖屏

    /* ######### ############ ############# ## ########### ### ###### ##### ### ####### #### ### ####### ...

  10. 0 vs null

    看图说话 0 如图所示: 0 表示有纸(值), 但是纸(值)是0. 所以取纸(值)的时可以取, 但是没法用. null 如图所示: null 表示没有纸(值), 是真的啥都没有, 现在你抽纸的时候会出 ...