微信小程序至wx.getUserInfo与wx.login接口应用分享

因为我已经将post进行封装了,所以对应部分请大家自己替换

  getUserInfo: function (cb,failcb) {
    var that = this;
    if (this.globalData.userInfo) {
      //已有登录信息
      typeof cb == "function" && cb(this.globalData);
      console.log('已有登录信息');
    } else {
      //无登录信息
      wx.getUserInfo({
        success: function (res) {
          wx.login({
            success: function (res1) {
              var code = res1.code;
              that.globalData.userInfo = res.userInfo;
              console.log('用户信息', that.globalData.userInfo);
              that.login(code, res, cb);
            }
          })
        }, fail: function (res) {
          typeof failcb == "function" && failcb(res);
          console.log('未授权',res);
        }
      })
    }
  },