//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    //var logs = wx.getStorageSync('logs') || []
    //logs.unshift(Date.now())
    //wx.setStorageSync('logs', logs)
    var _this = this;
    var userId = wx.getStorageSync('userId') || ''
    console.log(userId);
    
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        console.log(res.code);
        wx.request({
          url: _this.server + 'SmallProgram/WechatPosters/getUserInfo',
          data: {
            code: res.code
          },
          success: function (event) {
            console.log(event.data)
            //用户信息已经存在
            if (event.data.code == '10000') {
              //var pid = wx.getStorageSync('pid') || ''
              var userId = event.data.data.userId
              wx.setStorageSync('userId', userId)
            }
          }
        })
      }
    })   
  },
  globalData: {
    userInfo: null
  },
  server: 'https://seex.inner.iouou.cn/',
})