123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //app.js
- import {
- getMpOpenId
- } from "api/home"
- App({
- onLaunch: function () {
- // 展示本地存储能力
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now())
- wx.setStorageSync('logs', logs)
- // 登录
- wx.login({
- success: res => {
- // console.log("code:"+res.code);
-
- let code = res.code;
- // console.log("app.js code="+res.code);
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- getMpOpenId({
- code: code,
- stationId:1
- }).then(res => { // handle success
- // console.log("app.js openid:"+res.openid);
- // console.log("app.js unoiid " + res.unionid)
- this.mpOpenId = res.openid;
- this.globalData.unionId = res.unionId
- this.unionId = res.unionid
- // console.log(this.globalData)
- // console.log(this)
- }).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,//用户手机号
- mpOpenId: null,
- unionId:null,
- appId:'wxe1135cd390b38a54',//小程序的appid
- stationId: null, //加油站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 //实付金额
- }
- })
|