app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. App({
  2. globalData: {
  3. showAnimation: true,
  4. id: null,
  5. name: null,
  6. },
  7. onLaunch(options) {
  8. console.log(options, "onLaunch");
  9. // if (wx.getStorageSync('openId')) {
  10. // wx.request({
  11. // url: 'http://info.windd.cn:8080/test/applet/isExist',
  12. // method: "GET",
  13. // data: {
  14. // appletsId: wx.getStorageSync('openId')
  15. // },
  16. // success: (res) => {
  17. // console.log(res, "000000000000000000");
  18. // if (res.data.code == 0) {
  19. // wx.switchTab({
  20. // url: '/pages/index/index',
  21. // })
  22. // }
  23. // }
  24. // })
  25. // } else {
  26. // }
  27. // wx.login({
  28. // success: res => {
  29. // // 获取到用户的 code 之后:res.code
  30. // console.log("用户的code:" + res.code);
  31. // const appid = "wx1c015df104db7030"
  32. // const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  33. // let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  34. // wx.request({
  35. // // 自行补上自己的 APPID 和 SECRET
  36. // url: url,
  37. // success: res => {
  38. // // 获取到用户的 openid
  39. // console.log("用户的openid:" + res.data.openid);
  40. // wx.setStorageSync('openId', res.data.openid)
  41. // wx.request({
  42. // url: 'http://info.windd.cn:8080/test/applet/isExist',
  43. // method: "GET",
  44. // data: {
  45. // appletsId: wx.getStorageSync('openId')
  46. // },
  47. // success: (res) => {
  48. // console.log(res, "apppppppppppppppppppppppppp");
  49. // if (res.data.code == 0) {
  50. // if(res.data.data){
  51. // wx.setStorageSync('user', 'user');
  52. // }
  53. // }
  54. // }
  55. // })
  56. // }
  57. // });
  58. // }
  59. // });
  60. },
  61. onShow(options) {
  62. // Do something when show.
  63. },
  64. onHide() {
  65. // Do something when hide.
  66. },
  67. onError(msg) {
  68. console.log(msg)
  69. },
  70. getAuthKey: function () {
  71. var that = this;
  72. return new Promise(function (resolve, reject) {
  73. // 调用登录接口
  74. wx.login({
  75. success: function (res) {
  76. if (res.code) {
  77. console.log("用户的code:" + res.code);
  78. const appid = "wx1c015df104db7030"
  79. const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  80. let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  81. wx.request({
  82. // 自行补上自己的 APPID 和 SECRET
  83. url: url,
  84. success: res => {
  85. // 获取到用户的 openid
  86. console.log("用户的openid:" + res.data.openid);
  87. wx.setStorageSync('openId', res.data.openid)
  88. wx.request({
  89. url: 'http://10.16.4.7:7001/applet/isExist',
  90. method: "GET",
  91. data: {
  92. appletsId: wx.getStorageSync('openId')
  93. },
  94. success: (res) => {
  95. console.log(res, "apppppppppppppppppppppppppp");
  96. if (res.data.code == 0) {
  97. if (res.data.data) {
  98. wx.setStorageSync('user', 'user');
  99. }
  100. resolve(res);
  101. }
  102. }
  103. })
  104. }
  105. });
  106. } else {
  107. console.log('获取用户登录态失败!' + res.errMsg);
  108. var res = {
  109. status: 300,
  110. data: '错误'
  111. }
  112. reject('error');
  113. }
  114. }
  115. })
  116. });
  117. },
  118. })