获取用户信息
  1. wx.getUserInfo({
  2. withCredentials: true,
  3. success: function (res) {
  4. var nickName = res.userInfo.nickName;
  5. var avatarUrl = res.userInfo.avatarUrl;
  6. var gender = res.userInfo.gender;
  7. wx.login({
  8. success: function (res) {
  9. if (res.code) {
  10. var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
  11. wx.request({
  12. url: _this.globalData.domain + "Index/login",
  13. data: {
  14. encrypt_data: rsaData
  15. },
  16. method: "POST",
  17. header: {
  18. 'content-type': 'application/x-www-form-urlencoded'
  19. },
  20. success: function (res) {
  21. const user_id = res.data.data.user_id;
  22. var openid = res.data.data.openid;
  23. wx.setStorage({
  24. key: 'user_id',
  25. data: user_id,
  26. })
  27. wx.setStorage({
  28. key: 'openid',
  29. data: openid,
  30. })
  31. // 获取会员信息
  32. var rsaData = _this.rsaData({ user_id: user_id })
  33. wx.request({
  34. url: _this.globalData.domain + "user/get_user",
  35. data: {
  36. encrypt_data: rsaData,
  37. token: wx.getStorageSync('token')
  38. },
  39. header: {
  40. 'content-type': 'application/x-www-form-urlencoded'
  41. },
  42. method: "POST",
  43. success: function (res) {
  44.  
  45. },
  46. })
  47. },
  48. })
  49. }
  50. }
  51. })
  52. },
  53. fail: function (res) {
  54. var that = this;
  55. wx.openSetting({
  56. success(res) {
  57. if (!res.authSetting['scope.userInfo'] || !res.authSetting["scope.userLocation"]) {
  58. wx.authorize({
  59. scope: 'scope.userInfo',
  60. success(res) {
  61. // 失败之后再次登入
  62. wx.getUserInfo({
  63. withCredentials: true,
  64. success: function (res) {
  65. var nickName = res.userInfo.nickName;
  66. var avatarUrl = res.userInfo.avatarUrl;
  67. var gender = res.userInfo.gender;
  68. wx.login({
  69. success: function (res) {
  70. if (res.code) {
  71. var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
  72. wx.request({
  73. url: _this.globalData.domain + "Index/login",
  74. data: {
  75. encrypt_data: rsaData
  76. },
  77. method: "POST",
  78. header: {
  79. 'content-type': 'application/x-www-form-urlencoded'
  80. },
  81. success: function (res) {
  82. const user_id = res.data.data.user_id;
  83. var openid = res.data.data.openid;
  84. wx.setStorage({
  85. key: 'user_id',
  86. data: user_id,
  87. })
  88. wx.setStorage({
  89. key: 'openid',
  90. data: openid,
  91. })
  92. // 获取会员信息
  93. var rsaData = _this.rsaData({ user_id: user_id })
  94. wx.request({
  95. url: _this.globalData.domain + "user/get_user",
  96. data: {
  97. encrypt_data: rsaData,
  98. token: wx.getStorageSync('token')
  99. },
  100. header: {
  101. 'content-type': 'application/x-www-form-urlencoded'
  102. },
  103. method: "POST",
  104. success: function (res) {
  105.  
  106. },
  107. })
  108. },
  109. })
  110. }
  111. }
  112. })
  113. },
  114. })
  115. // 失败之后再次登入
  116. }, fail: (res) => {
  117. /*
  118. * 点击取消之后再次获取user_id 和openid
  119. */
  120. wx.showModal({
  121. title: '警告',
  122. content: '您点击了拒绝授权,将无法正常使用******的功能体验,请10分钟后再次点击授权,或者删除小程序重新进入',
  123. success: function (res) {
  124. if (res.cancel) {
  125. wx.openSetting({
  126. success: (res) => {
  127. // 失败之后再次登入
  128. wx.getUserInfo({
  129. withCredentials: true,
  130. success: function (res) {
  131. var nickName = res.userInfo.nickName;
  132. var avatarUrl = res.userInfo.avatarUrl;
  133. var gender = res.userInfo.gender;
  134. wx.login({
  135. success: function (res) {
  136. if (res.code) {
  137. var rsaData = _this.rsaData({ code: res.code, wx_appid: _this.globalData.appId, nickName: nickName, gender: gender, avatarUrl: avatarUrl })
  138. wx.request({
  139. url: _this.globalData.domain + "Index/login",
  140. data: {
  141. encrypt_data: rsaData
  142. },
  143. method: "POST",
  144. header: {
  145. 'content-type': 'application/x-www-form-urlencoded'
  146. },
  147. success: function (res) {
  148. const user_id = res.data.data.user_id;
  149. var openid = res.data.data.openid;
  150. wx.setStorage({
  151. key: 'user_id',
  152. data: user_id,
  153. })
  154. wx.setStorage({
  155. key: 'openid',
  156. data: openid,
  157. })
  158. // 获取会员信息
  159. var rsaData = _this.rsaData({ user_id: user_id })
  160. wx.request({
  161. url: _this.globalData.domain + "user/get_user",
  162. data: {
  163. encrypt_data: rsaData,
  164. token: wx.getStorageSync('token')
  165. },
  166. header: {
  167. 'content-type': 'application/x-www-form-urlencoded'
  168. },
  169. method: "POST",
  170. success: function (res) {
  171.  
  172. },
  173. })
  174. },
  175. })
  176. }
  177. }
  178. })
  179. },
  180. })
  181. // 失败之后再次登入
  182. }
  183. })
  184. }
  185. },
  186. })
  187. }
  188. })
  189. }
  190. }
  191. })
  192. }
  193. })

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

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

  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. Logistic回归计算过程的推导

    https://blog.csdn.net/ligang_csdn/article/details/53838743 https://blog.csdn.net/weixin_30014549/art ...

  2. 网易blog服务器关闭了,我曾经的大部分博文迁移至此,留作纪念。欢迎大家去我的简书blog~

    ARM时代过去了,另一个AI时代正在上演~ 这一次我看上了计算机视觉,一个依旧在发展,论文数量不断上升的技术领域,还有很多待研究的技术突破点,我可以玩的时间长一点了. 活到老,学到了.学以致用乐趣无穷 ...

  3. Flutter数据库Sqflite之增删改查

    Flutter数据库Sqflite之增删改查   简介 sqflite是Flutter的SQLite插件,支持iOS和Android,目前官方版本是sqflite1.1.3 sqflite插件地址:h ...

  4. CentOS 7编译OpenWRT

    安装必要的依赖 yum install subversion binutils bzip2 gcc gcc-c++ gawk gettext flex ncurses-devel zlib-devel ...

  5. "做中学"之“极客时间”课程学习指导

    目录 "做中学"之"极客时间"课程学习指导 所有课程都可以选的课程 Java程序设计 移动平台开发 网络攻防实践 信息安全系统设计基础 信息安全专业导论 极客时 ...

  6. style1

    <!doctype html> 我的简历 基本信息 姓名 张三 性别 男 应聘职位 WEb前端工程师 联系方式 手机 12312341234 Email joinefe@baidu.com ...

  7. vue+vuex 回退定位到初始位置

    先放出两张图(没错,你还在9012,做为一名资深设计师我唯一的技能点就是留白),简单说明下问题未做回退定位(从落地页回退,每次都回到A位置)想死啊有木有,每次都需要手动重新定位来选择,你大哥看到你做个 ...

  8. loadrunner常用函数集锦

    一.三个复制函数的区别: strcpy 原型:extern char *strcpy(char *dest,char *src);用法:#i nclude功能:把src所指由NULL结束的字符串复制到 ...

  9. php动态获取网页图片路径~

    <?phpheader("Content-type:text/html;charset=utf-8"); 请求的url $url = 'http://dsc.taobaocd ...

  10. [爬虫进阶]使用Jsoup取代你的一切网络请求方法(java,post,get,代理IP)

    [爬虫进阶]使用Jsoup取代你的一切网络请求方法(java,post,get,代理IP) 原文链接:https://www.cnblogs.com/blog5277/p/9334560.html 原 ...