testSAS.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // miniprogram/pages/testSAS/testSAS.js
  2. // const db = wx.cloud.database()
  3. const homeApi_empower = "https://aipush.aidsleep.cn";
  4. const token_empower = "b74fd5754c5ef24cf600c39194abdaeb";
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. intervalId: null,//解除授权定时任务
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. console.log('hasAuth===data='+wx.getStorageSync('hasAuth'));
  17. if(!wx.getStorageSync('userInfo_em') || !wx.getStorageSync('unionid') || !wx.getStorageSync('openid') || !wx.getStorageSync('hasAuth')){
  18. // wx.showModal({
  19. // title: '提示',
  20. // content: '请进行授权',
  21. // showCancel: false
  22. // });
  23. wx.showToast({
  24. title: '请进行授权',
  25. icon: 'none',
  26. duration: 2000
  27. });
  28. setTimeout(function() {
  29. wx.reLaunch({
  30. url: '/pages/empower/empower',
  31. })
  32. }, 2500) // 设置延时时间,单位为毫秒
  33. }else{
  34. if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  35. wx.showModal({
  36. title: '提示',
  37. content: '请先扫描房间二维码',
  38. showCancel: false
  39. });
  40. setTimeout(function () {
  41. wx.reLaunch({
  42. url: '/pages/scan/scan',
  43. })
  44. }, 2000) // 设置延时时间,单位为毫秒
  45. } else {
  46. var that = this;
  47. let hotelcodeTemp = '';
  48. let roomcodeTemp = '';
  49. if (wx.getStorageSync('res').result.split('|').length != 2) {
  50. wx.showModal({
  51. title: '提示',
  52. content: '房间二维码不正确,请重新扫码',
  53. showCancel: false
  54. });
  55. setTimeout(function () {
  56. wx.reLaunch({
  57. url: '/pages/scan/scan',
  58. })
  59. }, 2000) // 设置延时时间,单位为毫秒
  60. }
  61. hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
  62. roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
  63. console.log('hotelcodeTemp=+='+hotelcodeTemp);
  64. console.log('roomcodeTemp=+='+roomcodeTemp);
  65. const hotelEmpower = wx.getStorageSync('hotelEmpower');
  66. const roomEmpower = wx.getStorageSync('roomEmpower');
  67. if (hotelcodeTemp != hotelEmpower || roomcodeTemp != roomEmpower) {
  68. wx.showModal({
  69. title: '提示',
  70. content: '授权配置错误,或者您没有使用权限',
  71. showCancel: false
  72. });
  73. setTimeout(function () {
  74. wx.reLaunch({
  75. url: '/pages/scan/scan',
  76. })
  77. }, 2000) // 设置延时时间,单位为毫秒
  78. }
  79. }
  80. }
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. const app = getApp();
  92. app.globalData.selectedTabIndex = 3;
  93. this.getTabBar().setData({
  94. selected: 3
  95. })
  96. var that = this;
  97. if (!that.data.intervalId) {
  98. that.data.intervalId = setInterval(() => {
  99. // 这里执行你的代码
  100. console.log('testSAS页面:'+Date.now());
  101. if(wx.getStorageSync('userInfo_em') && wx.getStorageSync('unionid') && wx.getStorageSync('openid') && wx.getStorageSync('hasAuth')){
  102. wx.request({
  103. url: `${homeApi_empower}/wxstatus`,
  104. data: {
  105. unionid: wx.getStorageSync('unionid'),
  106. openid: wx.getStorageSync('openid'),
  107. //phoneNumber: that.data.phoneNumber,
  108. token: token_empower,
  109. },
  110. method: 'POST',
  111. success: function(intervalRes) {
  112. console.log('intervalRes='+JSON.stringify(intervalRes));
  113. console.log('intervalRes.data='+JSON.stringify(intervalRes.data));
  114. //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
  115. if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '0' ) {
  116. wx.showToast({
  117. title: '授权已过期',
  118. icon: 'none'
  119. });
  120. wx.removeStorageSync('userInfo_em');
  121. wx.removeStorageSync('phoneNumber');
  122. wx.removeStorageSync('unionid');
  123. wx.removeStorageSync('openid');
  124. wx.removeStorageSync('hasAuth');
  125. wx.removeStorageSync('hotelEmpower');
  126. wx.removeStorageSync('roomEmpower');
  127. setTimeout(function() {
  128. wx.reLaunch({
  129. url: '/pages/empower/empower',
  130. })
  131. }, 2000) // 设置延时时间,单位为毫秒
  132. }
  133. },
  134. });
  135. }
  136. }, 10000);
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })