App({ onLaunch: function () { if (my.canIUse('getUpdateManager')) { const updateManager = my.getUpdateManager() updateManager.onCheckForUpdate(function (res) { if (res.hasUpdate) { updateManager.onUpdateReady(function () { my.alert({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success: function (res) { updateManager.applyUpdate() } }) }) updateManager.onUpdateFailed(function () { my.alert({ title: '已经有新版本了哟~', content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' }) }) } }) } else { my.alert({ title: '提示', content: '当前支付宝版本过低,无法使用该功能,请升级到最新支付宝版本后重试。' }) } console.log(my.getStorageSync({ 'key': 'token' }).data, 'XXXXXXXXXXXXXXXXXXXXX') }, globalData: { statusBarHeight: my.getSystemInfoSync()['statusBarHeight'], windowHeight: my.getSystemInfoSync()['windowHeight'], imgUrl: 'http://resource.bike.hanyiyun.com/', screenHeight: '', login: false, platform: '', version: '', req: true, id: 0, times: 60, invalid: false, scanLength: 9,//车辆编码数 compatible: '', title: '禹见你', //全局修改此小程序名称 logoUrl: '../../img/logo.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png appid: '2021002147603404', //小程序的appid wxc5f328a92356183f--遇见你appid merchant_id: '1', url: 'https://api.mtu.ximengnaikang.com/api', //线上域名 // url: 'http://api.yutu.site.ximengnaikang.com/api', //本地域名 mapKey: 'GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ' //地图key值 }, request(api, params, method, req1) { var that = this; if (req1 == false) return; if (req1) { that.globalData.req = false; } if (my.getStorageSync({ 'key': 'token' }).data != '' || my.getStorageSync({ 'key': 'token' }).data != undefined) { if (req1 == true || req1 == undefined) { return new Promise((resolve, reject) => { my.request({ url: this.globalData.url + api, data: params, headers: { 'content-type': 'application/json', 'Accept': 'application/json', 'Cache-Control': 'no-cache', 'Authorization': my.getStorageSync({ 'key': 'token' }).data, 'merchant-id': this.globalData.merchant_id, 'source-type': 'alipay' }, method: method, success: (res) => { // console.log(res) if (res.status == 450) { return; } if (res.status != 200) { if (res.data.message == '订单不存在或订单已结算') { if (this.globalData.compatible) { my.reLaunch({ url: '/pages/compatible/index/index', }) } else { my.reLaunch({ url: '/pages/index/index', }) } return false; } else if (res.data.message == '运动中不能关锁') { return false; } if (res.message != undefined) { my.showToast({ content: res.message, icon: 'none', duration: 3000, mask: true }) } else if (res.data.message != undefined) { my.showToast({ content: res.data.message, icon: 'none', duration: 3000, mask: true }) } } console.log(res, 'token-------------------------------------------') resolve(res) }, fail: (err) => { if (err.status == 401) { var timeout; console.log('token过期') my.removeStorageSync({key:'token'}) my.removeStorageSync({key:'token_time'}) // this.token() my.reLaunch({ url: '/pages/index/index', }) } else if (err.status == 404) { my.navigateTo({ url: '/pages/undefind/undefind', }) } else { my.showToast({ content: err.data.message || err.data, icon: 'none', mask: true, duration: 3000, }); } console.log(err, 'qingqiushibai') reject(err, "请求失败") }, complete: () => { that.globalData.req = true } }) }) } } }, login() { let that = this let token = my.getStorageSync({ 'key': 'token' }).data let data = Math.round(new Date() / 1000); let tokenTime = my.getStorageSync({ 'key': 'token_time' }).data; let cha = data - tokenTime let data1 = 60 * 60 * 24 return new Promise((resolve, reject) => { if (token && cha < data1) { console.log(Math.round(new Date() / 1000), 'test--------') console.log(cha, 'test--------') console.log(data1, 'test-data1-------') return resolve(); } else { my.getAuthCode({ success: (res) => { // 发送 res.code 到后台换取 openId, sessionKey, unionId if (res.authCode) { console.log(res.authCode) // var data = { // 'code': res.authCode, // 'appid': that.globalData.appid, // // 'phone_detail': JSON.stringify(arr), // 'phone_detail': '', // 'invite_user_id': that.globalData.id, // 'language': 'zh' // }; var data = { 'code': res.authCode, 'appid': that.globalData.appid, 'type': 1 }; my.request({ url: that.globalData.url + '/auth/weapp-login', data: data, headers: { 'content-type': 'application/json', 'Accept': 'application/json', 'Cache-Control': 'no-cache', // 'Authorization': my.getStorageSync({ 'key': 'token' }).data, 'merchant-id': that.globalData.merchant_id, 'source-type': 'alipay' }, method: 'POST', success: (res) => { console.log(res, 'token') if (res.status == 401) { my.showToast({ content: '登陆失败,请重新登录', icon: 'none' }) setTimeout(function () { my.reLaunch({ url: '/pages/authorization/authorization', }) }, 1000) } else if (res.status != 200) { console.log(res, 'cesgu---------------') my.showToast({ content: '登录失败,请刷新', icon: 'none' }) } else { my.setStorageSync({ 'key': 'token', data: res.data.token }); my.setStorageSync({ 'key': 'session_key', data: res.data.session_key }); my.setStorageSync({ 'key': 'token_time', data: res.data.exp }); my.setStorageSync({ 'key': 'user_ID', data: res.data.user.id }); } resolve() }, fail: (err) => { my.showToast({ // content: err.message, content: '121212', icon: 'none' }) } }) } else { my.showToast({ content: res.errMsg, icon: none, }) } } }) } }) }, }) // App({ // onLaunch: function () { // // 登录 // var that = this; // my.getSystemInfo({ // success: res => { // console.log(res) // var system = res.system.trim().split(/\s+/)[1]; // } // }) // if (my.getStorageSync({'key':'midTimes'}).data != '') { // var time = my.getStorageSync({'key':'midTimes'}).data; // var timestamp = Date.parse(new Date()) / 1000; // if (time <= timestamp) { // console.log('midtimes过期') // my.setStorageSync({'key':'midTimes',data:''}) // } // } // var time = my.getStorageSync({'key':'token_time'}).data; // var timestamp = Date.parse(new Date()); // if (time <= timestamp / 1000) { // console.log('token过期') // my.removeStorageSync('token_time') // } // if (my.canIUse('getUpdateManager')) { // const updateManager = my.getUpdateManager() // updateManager.onCheckForUpdate(function (res) { // if (res.hasUpdate) { // updateManager.onUpdateReady(function () { // my.alert({ // title: '更新提示', // content: '新版本已经准备好,是否重启应用?', // success: function (res) { // updateManager.applyUpdate() // } // }) // }) // updateManager.onUpdateFailed(function () { // my.alert({ // title: '已经有新版本了哟~', // content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~' // }) // }) // } // }) // } else { // my.alert({ // title: '提示', // content: '当前支付宝版本过低,无法使用该功能,请升级到最新支付宝版本后重试。' // }) // } // //登录 // }, // globalData: { // statusBarHeight: my.getSystemInfoSync()['statusBarHeight'], // windowHeight: my.getSystemInfoSync()['windowHeight'], // imgUrl: 'http://resource.bike.hanyiyun.com/', // screenHeight: '', // login: false, // platform: '', // version: '', // req: true, // id: 0, // times: 60, // invalid: false, // compatible: '', // title: '禹见你', //全局修改此小程序名称 // logoUrl: '../../img/logo.png', //logo图片路径 网络图片/本地图片 dejin.png shanxianLg.png yuzhouLg.png dingding.png // appid: '2021002147603404', //小程序的appid wxc5f328a92356183f--遇见你appid // merchant_id: '1', // url: 'https://api.mtu.ximengnaikang.com/api', //线上域名 // // url: 'http://api.yutu.site.ximengnaikang.com/api', //本地域名 // mapKey: 'GTLBZ-F6BKO-5EDWH-SDHIX-K2ART-O2FRQ' //地图key值 // }, // request(api, params, method, req1) { // var that = this; // if (req1 == false) return; // if (req1) { // that.globalData.req = false; // } // if (my.getStorageSync({'key':'token'}).data != '' || my.getStorageSync({'key':'token'}).data != undefined) { // if (req1 == true || req1 == undefined) { // return new Promise((resolve, reject) => { // my.request({ // url: this.globalData.url + api, // data: params, // headers: { // 'content-type': 'application/json', // 'Accept': 'application/json', // 'Cache-Control': 'no-cache', // 'Authorization': my.getStorageSync({'key':'token'}).data, // 'merchant-id': this.globalData.merchant_id, // 'source-type': 'alipay' // }, // method: method, // success: (res) => { // resolve(res) // // console.log(res) // if (res.status == 450) { // return; // } // if (res.status != 200) { // if (res.data.message == '订单不存在或订单已结算') { // if (this.globalData.compatible) { // my.reLaunch({ // url: '/pages/compatible/index/index', // }) // } else { // my.reLaunch({ // url: '/pages/index/index', // }) // } // return false; // } else if (res.data.message == '运动中不能关锁') { // return false; // } // if (res.message != undefined) { // my.showToast({ // content: res.message, // icon: 'none', // duration: 3000, // mask: true // }) // } else if (res.data.message != undefined) { // my.showToast({ // content: res.data.message, // icon: 'none', // duration: 3000, // mask: true // }) // } // } // if (res.status == 401) { // var timeout; // my.removeStorageSync('token') // my.removeStorageSync('token_time') // // this.token() // my.reLaunch({ // url: '/pages/index/index', // }) // } else if (res.status == 404) { // my.navigateTo({ // url: '/pages/undefind/undefind', // }) // } // }, // fail: (err) => { // my.showToast({ // content: err.data.message || err.data, // icon: 'none', // mask: true, // duration: 3000, // }); // console.log(err,'qingqiushibai') // reject(err,"请求失败") // }, // complete: () => { // that.globalData.req = true // } // }) // }) // } // } // }, // token:function(){ // let that=this // my.getAuthCode({ // success: function (res) { // my.getSystemInfo({ // success(res) { // console.log(arr) // var arr = [{ // label: '品牌', // type: 'brand', // value: res.brand // }, // { // label: '型号', // type: 'model', // value: res.model // }, // { // label: '系统平台', // type: 'platform', // value: res.platform // }, // { // label: '系统版本', // type: 'system', // value: res.system // }, // { // label: '支付宝版本', // type: 'version', // value: res.version // }, // { // label: '小程序版本', // type: 'SDKVersion', // value: res.SDKVersion // }, // { // label: '定位状态', // type: 'locationEnabled', // value: res.locationEnabled ? '开' : '关' // }, // { // label: '定位授权', // type: 'locationAuthorized', // value: res.locationAuthorized ? '已授权' : '未授权' // } // ] // } // }) // // 发送 res.code 到后台换取 openId, sessionKey, unionId // console.log(res.code) // var data = { // 'code': res.authCode, // 'appid': that.globalData.appid, // 'type': 1 // }; // my.request({ // url: that.globalData.url + '/auth/weapp-login', // data: data, // headers: { // 'content-type': 'application/json', // 'Accept': 'application/json', // 'Cache-Control': 'no-cache', // 'Authorization': my.getStorageSync({'key':'token'}).data, // 'merchant-id': that.globalData.merchant_id // }, // method:'POST', // success:(res)=>{ // my.setStorageSync({'key':'token',data:res.data.token}); // my.setStorageSync({'key':'session_key',data:res.data.session_key}); // my.setStorageSync({'key':'token_time',data:res.data.exp}); // my.setStorageSync({'key':'user_ID',data:res.data.user.id}); // },err:(err=>{ // console.log(err,'登录错误---------------------------------') // }) // }) // } // }) // } // })