app.js 4.0 KB

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