//app.js import { getMpOpenId } from "api/home" import { appId, stationId } from "./setting" App({ onLaunch: function () { // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) // 登录 wx.login({ success: res => { // console.log("code:" + res); let code = res.code; // console.log("app.js code="+res.code); // 发送 res.code 到后台换取 openId, sessionKey, unionId getMpOpenId({ code: code, stationId }).then(res => { // handle success console.log(res) // console.log("app.js openid:"+res.openid); // console.log("app.js unoiid " + res.unionid) this.globalData.openId = res.openId; this.globalData.unionId = res.unionId; console.log(this.globalData.unionId) }).catch(error => { // handle error console.log(error); }) } }) // 获取用户信息 wx.getSetting({ success: res => { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 wx.getUserInfo({ success: res => { // 可以将 res 发送给后台解码出 unionId this.globalData.userInfo = res.userInfo // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 if (this.userInfoReadyCallback) { this.userInfoReadyCallback(res) } } }) } } }) }, globalData: { mpVersion:null,//小程序当前是开发版?体验版?正式版? userInfo: null, //用户信息 phoneNumber:null,//用户手机号 openId:null, unionId:null, appId, stationId, //加油站ID stationName: null, //油站名称 picUrl: null, //油站图片URL mno: null, //油站绑定的商户号 oilGunNum: null, //油枪号 oilGunName: null, //油品名 oilPrice: null, //油品价格 orderNo: null, //订单号 orderAmount: null, //订单金额 manJianAmount: null, //满减金额 liJianAmount: null, //立减金额 youHuiAmount: null, //优惠券金额 payAmount: null //实付金额 } })