微信小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

116 wiersze
3.5 KiB

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