app.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // app.js
  2. const homeApi_empower = "https://aipush.aidsleep.cn";
  3. App({
  4. onLaunch() {
  5. wx.hideTabBar()
  6. // 展示本地存储能力
  7. // const logs = wx.getStorageSync('logs') || []
  8. // logs.unshift(Date.now())
  9. // wx.setStorageSync('logs', logs)
  10. // this.globalData.selectedTabIndex = wx.getStorageSync("selectedTabIndex") || 0;
  11. // 登录
  12. wx.login({
  13. success: res => {
  14. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  15. wx.request({
  16. url: `${homeApi_empower}/wxssk`,
  17. method: 'POST',
  18. data: {
  19. code: res.code,
  20. },
  21. success: function (loginRes) {
  22. // 处理服务器返回的结果
  23. console.log('登录获取结果:', loginRes.data);
  24. if (loginRes.data) {
  25. wx.setStorageSync("openid", loginRes.data.openid);
  26. wx.setStorageSync("token", loginRes.data.token);
  27. wx.setStorageSync("unionid", loginRes.data.unionid);
  28. // 判断扫码控制权限
  29. wx.request({
  30. url: `${homeApi_empower}/wxstatus`,
  31. data: {
  32. unionid: wx.getStorageSync('unionid'),
  33. openid: wx.getStorageSync('openid'),
  34. token: wx.getStorageSync('token'),
  35. },
  36. method: 'POST',
  37. success: function (intervalRes) {
  38. console.log('intervalRes=' + JSON.stringify(intervalRes));
  39. console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
  40. //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
  41. if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
  42. wx.setStorageSync('hasHotelAuth', true);
  43. wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
  44. wx.setStorageSync('roomEmpower', intervalRes.data.room);
  45. } else {
  46. wx.setStorageSync('hasHotelAuth', false);
  47. }
  48. },
  49. fail: function (error) {
  50. }
  51. });
  52. // 判断今日睡眠报告权限
  53. wx.request({
  54. url: 'https://aipush.aidsleep.cn/srpwithrange',
  55. method: 'POST',
  56. data: {
  57. token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
  58. udi: wx.getStorageSync('unionid'),
  59. pg: 1,
  60. lm: 1
  61. },
  62. success: (res) => {
  63. var loadData = res.data.data;
  64. if ((Array.isArray(loadData) && loadData.length > 0) || (loadData && !Array.isArray(loadData)) ) {
  65. wx.setStorageSync('hasReportAuth', true);
  66. } else {
  67. wx.setStorageSync('hasReportAuth', false);
  68. }
  69. },
  70. fail: () => {
  71. wx.setStorageSync('hasReportAuth', false);
  72. }
  73. });
  74. }
  75. }
  76. })
  77. }
  78. })
  79. },
  80. onShow() {
  81. },
  82. globalData: {
  83. userInfo: null,
  84. selectedTabIndex: 0
  85. }
  86. })