authorization.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. const app = getApp()
  2. var arr = [];
  3. Page({
  4. data: {
  5. //测试.
  6. versions: false,
  7. token: '',
  8. img: app.globalData.imgUrl,
  9. title: app.globalData.title,
  10. logoUrl: '',
  11. bind_mobile: 0,
  12. session_key: ''
  13. },
  14. onLoad: function (options) {
  15. var that = this;
  16. my.setNavigationBar({
  17. title: app.globalData.title
  18. })
  19. this.setData({
  20. logoUrl: app.globalData.logoUrl
  21. })
  22. },
  23. skipXieyi:function(){
  24. my.navigateTo({
  25. url: '/pages/agreement/agreement',
  26. })
  27. },
  28. onGotUserInfo: function (e) {
  29. console.log(e)
  30. if (e.detail.errMsg == "getUserInfo:fail auth deny") {
  31. my.showToast({
  32. content: '授权失败请重试',
  33. icon: 'none'
  34. })
  35. } else {
  36. my.showLoading({
  37. content: '登陆中请稍等...',
  38. mask: true
  39. })
  40. if (e.detail.rawData) {
  41. var data = e.detail.userInfo
  42. my.setStorageSync({ 'key': 'userInfo', data: data })
  43. if (my.getStorageSync({ 'key': 'home' }).data.id != undefined) {
  44. data.area_id = my.getStorageSync({ 'key': 'home' }).data.id
  45. }
  46. console.log(data)
  47. app.request("/auth/weapp-userinfo-sync", data, "POST").then(res => {
  48. if (res.status == 200) {
  49. my.showToast({
  50. content: '授权成功',
  51. icon: 'none'
  52. })
  53. my.setStorageSync({ 'key': 'userInfo', data: res.data })
  54. // my.navigateBack()
  55. if (app.globalData.compatible) {
  56. console.log(app.globalData.compatible)
  57. my.redirectTo({
  58. url: '/pages/compatible/index/index',
  59. })
  60. } else {
  61. my.redirectTo({
  62. url: '/pages/index/index',
  63. })
  64. }
  65. } else {
  66. my.showToast({
  67. content: '登陆失败请重试',
  68. icon: 'none'
  69. })
  70. my.redirectTo({
  71. url: '/pages/index/index',
  72. })
  73. }
  74. })
  75. } else {
  76. my.showToast({
  77. content: '授权失败',
  78. icon: 'none'
  79. })
  80. }
  81. }
  82. },
  83. onAuthError: function () {
  84. my.showToast({
  85. content: '授权失败请重试',
  86. type: 'none'
  87. });
  88. },
  89. getUserPhoneNumber: function (e) {
  90. console.log(e)
  91. my.getPhoneNumber({
  92. success: (res) => {
  93. console.log(res, "KKKKKKKKKKK")
  94. let encryptedData = JSON.parse(res.response).response;
  95. //userObject.phoneInfo = res.response;
  96. console.log(encryptedData);
  97. //手机号解密请求
  98. // phoneAuth(res.response);
  99. // my.alert({
  100. // title: encryptedData,
  101. // });4nbLCy+uBSvO8waRPGv3/EsHNqpa68oN8bPAyJqGjCT6UAVIaMuwChCdRsJkrsKRT3lGHdqyaET7YL2IptOLp7pZYW6w4wl9BHDLmx6V9kRindBZMBTYKzp7ov99o/E6rG3fZZCXSNA59aiKMojMA+JIzMRuo3GRBOcq0YEml6I=
  102. if (encryptedData.length == 172) return;
  103. let data = {
  104. phone_detail: JSON.stringify(arr),
  105. type: '3',
  106. session_key: encryptedData,
  107. auth_id: this.data.auth_id
  108. }
  109. app.request('/auth/mobileLogin', data, 'POST', app.globalData.req).then(res => {
  110. console.log(res, "PPPPppp")
  111. my.setStorageSync({ key: 'userInfo', data: res.data.user })
  112. my.setStorageSync({ key: 'token', data: res.data.token });
  113. console.log(my.getStorageSync({ key: 'token' }))
  114. // my.setStorageSync('token', res.data.token)
  115. // my.setStorageSync('token_time', res.data.exp)
  116. // my.setStorageSync('userInfo', res.data.user)
  117. my.reLaunch({
  118. url: '/pages/index/index',
  119. })
  120. })
  121. },
  122. fail: (res) => {
  123. console.log(res, "error");
  124. }
  125. })
  126. },
  127. //手机号登陆
  128. phoneLogin: function () {
  129. my.navigateTo({
  130. url: '/pages/phonelogin/phonelogin',
  131. })
  132. },
  133. //暂不登录
  134. noSign: function () {
  135. my.reLaunch({
  136. url: '/pages/index/index',
  137. })
  138. },
  139. onReady: function () {
  140. },
  141. onShow: function () {
  142. my.hideBackHome()
  143. },
  144. onHide: function () {
  145. },
  146. onUnload: function () {
  147. },
  148. onPullDownRefresh: function () {
  149. },
  150. onReachBottom: function () {
  151. },
  152. onShareAppMessage: function () {
  153. }
  154. })