authorization.js 4.3 KB

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