| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- // logs.js
- const util = require('../../utils/util.js')
- const homeApi = "https://aipush.aidsleep.cn";
- const token = "b74fd5754c5ef24cf600c39194abdaeb";
- const homeApi_empower = "https://aipush.aidsleep.cn";
- const token_empower = "b74fd5754c5ef24cf600c39194abdaeb";
- Page({
- data: {
- logs: [],
- canGetPhoneNumber: false,
- intervalId1: null,
- },
- onSaveExitState: function() {
- // wx.clearStorage();
- console.log("onSaveExitState=");
- // 返回保存的数据和超时时间(可选)
- return {
- expireTimeStamp: Date.now() + 24 * 60 * 60 * 1000 // 超时时间戳,例如设置为1天后过期
- };
- },
- //扫码
- tapScan(){
- wx.scanCode({
- success: function(res) {
- console.log('扫码获取的参数',res);
- // wx.clearStorage();
- wx.setStorageSync('res',res);
- wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000); // 超时时间戳,例如设置为2小时后过期
-
- if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
- wx.showModal({
- title: '提示',
- content: '请先扫描房间二维码',
- showCancel: false
- });
-
- setTimeout(function () {
- wx.reLaunch({
- url: '/pages/scan/scan',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- } else if (wx.getStorageSync('res').result.split('|').length != 2) {
- wx.showModal({
- title: '提示',
- content: '房间二维码不正确,请重新扫码',
- showCancel: false
- });
- } else {
-
- let hotelcodeTemp = '';
- let roomcodeTemp = '';
-
- hotelcodeTemp = wx.getStorageSync('res').result.split('|')[0];
- roomcodeTemp = wx.getStorageSync('res').result.split('|')[1];
- console.log('hotelcodeTemp=+='+hotelcodeTemp);
- console.log('roomcodeTemp=+='+roomcodeTemp);
- const hotelEmpower = wx.getStorageSync('hotelEmpower');
- const roomEmpower = wx.getStorageSync('roomEmpower');
- console.log('hotelEmpower=+='+hotelEmpower);
- console.log('roomEmpower=+='+roomEmpower);
- console.log('roomEmpower=+='+JSON.stringify(roomEmpower));
- if (hotelcodeTemp != hotelEmpower || roomcodeTemp != roomEmpower) {
- wx.showModal({
- title: '提示',
- content: '授权配置错误,或者您没有使用权限',
- showCancel: false
- });
- }else{
- wx.reLaunch({
- url: '/pages/index/index?res='+res,//传res
- })
- }
- }
- }
- })
- },
- onLoad() {
- console.log("scan页面");
-
- console.log('hasAuth===data='+wx.getStorageSync('hasAuth'));
- if(!wx.getStorageSync('userInfo_em') || !wx.getStorageSync('unionid') || !wx.getStorageSync('openid') || !wx.getStorageSync('hasAuth')){
- // wx.showModal({
- // title: '提示',
- // content: '请进行授权',
- // showCancel: false
- // });
- wx.showToast({
- title: '请进行授权',
- icon: 'none',
- duration: 2000
- });
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/empower/empower',
- })
- }, 2500) // 设置延时时间,单位为毫秒
- }else{
-
- }
-
- },
- startInterval: function () {
- // 使用 setInterval 创建定时任务,每8秒执行一次 this.myMethod 方法
- var that = this;
- that.clearInterval();
- // 定时器,执行授权过期判断,每10秒执行一次
- this.data.intervalId1 = setInterval(() => {
- // 这里执行你的代码
- console.log('scan页面:'+Date.now());
- if(wx.getStorageSync('userInfo_em') && wx.getStorageSync('unionid') && wx.getStorageSync('openid') && wx.getStorageSync('hasAuth')){
- wx.request({
- url: `${homeApi_empower}/wxstatus`,
- data: {
- unionid: wx.getStorageSync('unionid'),
- openid: wx.getStorageSync('openid'),
- //phoneNumber: that.data.phoneNumber,
- token: token_empower,
- },
- method: 'POST',
- success: function(intervalRes) {
- console.log('intervalRes='+JSON.stringify(intervalRes));
- console.log('intervalRes.data='+JSON.stringify(intervalRes.data));
- //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
- if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '0' ) {
- wx.showToast({
- title: '授权已过期',
- icon: 'none'
- });
- wx.removeStorageSync('userInfo_em');
- wx.removeStorageSync('phoneNumber');
- wx.removeStorageSync('unionid');
- wx.removeStorageSync('openid');
- wx.removeStorageSync('hasAuth');
- wx.removeStorageSync('hotelEmpower');
- wx.removeStorageSync('roomEmpower');
- setTimeout(function() {
- wx.reLaunch({
- url: '/pages/empower/empower',
- })
- }, 2000) // 设置延时时间,单位为毫秒
- }
- },
- });
- }
-
- }, 10000);
- },
- clearInterval: function () {
- if (this.data.intervalId1) {
- clearInterval(this.data.intervalId1);
- this.data.intervalId1 = null; // 可选,但建议清除以避免潜在的错误
- }
- },
- onHide() {
- this.clearInterval();
- },
- onUnload() {
- this.clearInterval();
- },
- onShow: function (options) {
- this.startInterval();
- },
- login: function() {
- var that = this;
- wx.login({
- success: res => {
- if (res.code) {
- // 发送 code 到服务器换取 session_key, openid
- wx.request({
- url: 'https://yourserver.com/api/login',
- data: {
- code: res.code
- },
- success: function(loginRes) {
- if (loginRes.data.success) {
- wx.setStorageSync('session_key', loginRes.data.session_key);
- wx.setStorageSync('openid', loginRes.data.openid);
- // 可以在这里提示用户进行手机号授权
- this.setData({
- canGetPhoneNumber: true
- });
- }
- }
- });
- }
- }
- });
- },
- getPhoneNumber: function(e) {
- if (e.detail.errMsg !== "getPhoneNumber:ok") {
- return;
- }
- const { encryptedData, iv } = e.detail;
- wx.request({
- url: 'https://yourserver.com/api/decrypt_phone',
- data: {
- encryptedData,
- iv,
- session_key: wx.getStorageSync('session_key')
- },
- success: function(decryptRes) {
- if (decryptRes.data.success) {
- console.log('解密后的手机号:', decryptRes.data.phoneNumber);
- // 处理解密后的手机号
- }
- }
- });
- },
-
- // 绑定按钮点击事件
- bindGetPhoneNumber: function() {
- if (this.data.canGetPhoneNumber) {
- wx.getPhoneNumber({
- success: this.getPhoneNumber
- });
- }
- }
- })
|