App({
  globalData: {
    // userInfo:null,      
    appId: 'xxx',
    key: 'xxx'   //AppSecret
  },
  onLaunch: function () {
    wx.request({
      url: 'https://m.zuihuibi.cn/api/authorize/obtainToken',
      method:'POST',
      data:{
        ticket:'miniPro'
      },
      success:function(response){
        wx.setStorageSync('X-Authorization', response.data.data.token);
        wx.login({
          success: function (res) {
            if (res.code) {
              //发起网络请求
              wx.request({
                url: 'https://m.zuihuibi.cn/api/jscode2session',
                method: 'POST',
                header: { 'X-Authorization': response.data.data.token },
                data: {
                  js_code: res.code
                },
                success: function (res) {
                  wx.setStorageSync('openId', res.data.data.openid)
                }
              })
            } else {
              console.log('登录失败！' + res.errMsg)
            }
          }
        });
        // 可以通过 wx.getSetting 先查询一下用户是否授权了 "scope.record" 这个 scope
        wx.getSetting({
          success(res) {
            if (!res.authSetting['scope.writePhotosAlbum']) {
              wx.authorize({
                scope: 'scope.writePhotosAlbum',
                success() {
                  wx.writePhotosAlbum()
                }
              })
            }
          }
        })
      }
    })
  }
})