//app.js App({ globalData: { // publicUrl: 'http://10.16.10.139:8090', //luyu publicUrl2: 'http://10.16.4.19:8090', //huyubo publicUrl: 'https://sqdx.windd.cn', //fwq // publicUrl2: 'https://sqdx.windd.cn', //fwq }, getSessionkey() { var sessionKey = ""; var _this = this; wx.checkSession({ success: () => { console.log("我有缓存") var sessionKey = wx.getStorageSync('sessionKey'); return sessionKey; }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); return sessionKey; } }) } }) } }) } })