// app.js import './utils/umtrack-wx'; App({ umengConfig: { appKey: '6260d691d024421570c69177', //由友盟分配的APP_KEY // 使用Openid进行统计,此项为false时将使用友盟+uuid进行用户统计。 // 使用Openid来统计微信小程序的用户,会使统计的指标更为准确,对系统准确性要求高的应用推荐使用Openid。 useOpenid: true, // 使用openid进行统计时,是否授权友盟自动获取Openid, // 如若需要,请到友盟后台"设置管理-应用信息"(https://mp.umeng.com/setting/appset)中设置appId及secret autoGetOpenid: false, debug: true, //是否打开调试模式 uploadUserInfo: true // 自动上传用户信息,设为false取消上传,默认为false }, onLaunch() { // 展示本地存储能力 const logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) this.loginGettoken() }, globalData: { userInfo: null, token: '', gameurl: ''// 游戏链接 }, //登录-获取token loginGettoken(){ let that = this wx.setStorageSync('token', '') wx.setStorageSync('userInfo', '') wx.login({ success (res) { if (res.code) { //发起网络请求 wx.request({ url:'https://cktest.2weisou.com/meta/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'', method: "POST", data: { }, header: { Authorization: "Basic YXBwbGV0OmFwcGxldA==", }, success(res1) { if (res1.statusCode == 200) { that.globalData.token = res1.data.access_token that.globalData.userInfo = res1.data.user_info // console.log(that.globalData.token) // console.log(that.globalData.userInfo) wx.setStorageSync('token', res1.data.access_token) wx.setStorageSync('userInfo', res1.data.user_info) } } }) } else { console.log('登录失败!' + res.errMsg) } } }) }, })