App({ onLaunch: function() { var i = this; wx.getSystemInfo({ success: function(t) { i.globalData.windowHeight = t.windowHeight, i.globalData.windowWidth = t.windowWidth; } }); this.getopenid() }, globalData: { windowHeight: null, windowWidth: null }, getTotal:function (){ wx.request({ url: 'https://a1.miniappapi.com/api/65d1a78fe4d99', data: { app_wxid: wx.getStorageSync('openid'), app_appid: getApp().globalData.appid }, header: { 'Access-Token': getApp().globalData.AccessToken }, success (res) { console.log(wx.getStorageSync('openid')) } }) }, getopenid:function(){ if (!wx.getStorageSync('openid')){ wx.login({ success (res) { if (res.code) { //发起网络请求 // console.log(res.code) wx.request({ url: 'https://a1.miniappapi.com/api/65d1a7b12cb5e', data: { code: res.code, appid:getApp().globalData.appid }, header: { 'Access-Token': getApp().globalData.AccessToken }, success (re) { console.log(re.data.data) try { // 将openid存储到本地存储中 wx.setStorageSync('openid', re.data.data.openid); // console.log('OpenID存储成功'); } catch (e) { // 存储失败的处理逻辑 console.error('OpenID存储失败', e); } } }) } else { console.log('登录失败!' + res.errMsg) } } }) } }, globalData: { userInfo: null, appid: 'wx9c620219025842e7', AccessToken:'yyxsRMusKlOEAxwMGFXaqBKldDIzElAf' } });