xcx/app.js

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 获取用户信息
    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)
              }
            }
          })
        }else{
          
        }
      }
    });
    var userId = wx.getStorageSync('userId');
    if (userId == null || userId <= 0) {
      this.getUserLogin();
    }
   
  },
  getUserLogin: function (callback) {
    var that = this;
    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        if (res.code) {
          wx.getUserInfo({
            withCredentials:false,
            success: resUserInfo => {
              if (resUserInfo) {
                that.globalData.userInfo = resUserInfo.userInfo
                //发起网络请求
                wx.request({
                  url: that.globalData.apiUrl,
                  data: {
                    code: res.code,
                    opt: 'onLogin'
                  },
                  header: {
                    'content-type': 'application/json'
                  },
                  success: function (res) {
                    wx.request({
                      url: that.globalData.apiUrl,
后面还有 48 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。