import { ApiModel } from './utils/api'; App({ onLaunch() { //自动登录 if (wx.getStorageSync('userMsg').token && ![1007, 1008, 1155].includes(wx.getLaunchOptionsSync().scene)) this.globalData.http.basic({ "classname": "webmanage.site.site", "method": "querySite_Parameter", "content": {} }).then(res => { console.log("验证登录", res) if (res.msg == '成功') { const loginMsg = require("./pages/login/modules/login"); loginMsg.query_userauth(); } }) }, initSocket() { let that = this; this.globalData.SocketTask = wx.connectSocket({ // url: 'wss://meida.cnyunl.com/yos/webSocket/' + wx.getStorageSync('userMsg').token, url: 'ws://192.168.3.111:8100/yos/webSocket/' + wx.getStorageSync('userMsg').token, complete: (res) => { console.log(res) } }) this.globalData.SocketTask.onOpen(function (res) { that.globalData.socketEstablish = true; }) this.globalData.SocketTask.onMessage(function (res) { that.globalData.socket.callback(res) let data = JSON.parse(res.data); if (data.message.type == 'pay') { that.globalData.http.basic({ "classname": "system.payorder.payorder", "method": "query_userauth", content: { nocache: true } }).then(res => { console.log('更新付费信息', res) wx.setStorageSync('userauth', res.data); wx.showToast({ title: '应用付费信息已更新', icon: "none" }) getCurrentPages().find(v => v.__route__ == 'pages/tabbar/home/index').refreshData(); }); } }) this.globalData.SocketTask.onError(function (res) { that.globalData.socketEstablish = false; }) this.globalData.SocketTask.onClose(function (res) { that.globalData.socketEstablish = false; }) }, globalData: { http: new ApiModel(), //接口文件 queryPer: require("./utils/queryPermissions"), //权限查询 socketEstablish: false, //是否已经建立socket SocketTask: '', // Socket方法 socket: { // Socket回调 that: null, //保存this callback: function () {} }, }, })