微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

login.js 3.6 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // pages/index/index.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. import * as STORAGE from '../../../utils/storage'
  5. const APP = getApp();
  6. Page({
  7. data: {
  8. isIPhoneX:false,
  9. privacyCheck:true //用户协议
  10. },
  11. onLoad: function (options) {
  12. this.setData({
  13. isIPhoneX:UTIL.isIPhoneX()
  14. })
  15. this.automaticLogin()
  16. },
  17. //自动登录
  18. automaticLogin(){
  19. let automatic = STORAGE.getToken();
  20. let getOpenId = STORAGE.getOpenId();
  21. if(automatic == '' && getOpenId ==''){
  22. console.log();
  23. UTIL.getCOdeFromWX({
  24. complate: (code) => {
  25. let sendData = {
  26. code: code
  27. }
  28. UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
  29. success: (res) => {
  30. if (res.code == API.SUCCESS_CODE) {
  31. wx.navigateTo({
  32. url: '/pages/index/index',
  33. })
  34. }
  35. }
  36. })
  37. }
  38. });
  39. }else{
  40. // wx.navigateTo({
  41. // url: '/pages/index/index',
  42. // })
  43. }
  44. },
  45. //用户隐私协议选项
  46. checkboxChange: function(res) {
  47. let checkStatus = false;
  48. if(res.detail.value.length!=0){
  49. checkStatus = true;
  50. }else{
  51. checkStatus = false;
  52. }
  53. this.setData({
  54. privacyCheck:checkStatus
  55. })
  56. },
  57. //微信一键登录授权
  58. getPhoneNumber: function(res) {
  59. let that = this;
  60. let {
  61. detail
  62. } = res;
  63. if (!detail.encryptedData) {
  64. //允许授权
  65. APP.showToast("未获取到手机号码,注册失败!");
  66. return;
  67. }else if(this.data.privacyCheck == false){
  68. APP.showToast("请阅读并同意用户协议和隐私政策!");
  69. return;
  70. }
  71. let sendData = {
  72. sessionKey:STORAGE.getSessionKey(),
  73. iv:detail.iv,
  74. encryptedData:detail.encryptedData
  75. }
  76. UTIL.httpRequestNoneDetal(API.URL_POST_DECRYPTEDWXDATA, sendData,"POST",{
  77. success: (res) => {
  78. console.log(res)
  79. if (res.code == API.SUCCESS_CODE) {
  80. let phoneNumber = res.data.phoneNumber;
  81. //微信手机号码绑定
  82. that.wxUserBand(phoneNumber)
  83. // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  84. } else {
  85. //待删
  86. UTIL.showToastNoneIcon(res.msg)
  87. }
  88. },
  89. fail: (res) => {
  90. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  91. }
  92. });
  93. },
  94. wxUserBand(phone){
  95. let sendData = {
  96. openId:STORAGE.getOpenId(),
  97. phonenumber:phone
  98. }
  99. UTIL.httpRequestNoneDetal(API.URL_POST_USERBAND, sendData,"POST",{
  100. success: (res) => {
  101. if (res.code == API.SUCCESS_CODE) {
  102. wx.navigateTo({
  103. url: '/pages/index/index',
  104. })
  105. }else{
  106. UTIL.showToastNoneIcon(res.msg)
  107. }
  108. },
  109. fail: (res) => {
  110. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  111. }
  112. });
  113. console.log(sendData)
  114. //
  115. }
  116. })