Sanakey
2022-10-28 0e185fa6db8e3f4209e63c079750a26fe3feddaa
app.js
@@ -2,6 +2,7 @@
// import  {Http} from "/utils/http-p.js"
import { promisifyAll } from './utils/wx-promise-pro'
import { Request } from './utils/http'
import emitter from './utils/eventBus'
import { updateManager } from './utils/appExtends'
import {webSocket, socketReconnect} from './utils/websocket'
let livePlayer = requirePlugin('live-player-plugin');
@@ -12,11 +13,13 @@
  onLaunch: async function (options) {
    console.log('小程序onLaunch事件', options);
    this.isFirstOpenApp = true;
    var FromUserId = this.getFromUserId(options);
    var {FromUserId,FURID} = this.getFromUserId(options);
    this.globalData.FromOpenId = options.query.FromOpenId || '';
    // this.globalData.ReferrerOpenId = options.query.ReferrerOpenId || '';
    this.globalData.FromUserId = FromUserId || '';
    this.globalData.FURID = FURID || '';
    this.globalData.tempFromUserId = this.globalData.FromUserId;
    this.globalData.emitter = emitter;
    console.log('FromOpenId是', this.globalData.FromOpenId);
    console.log('FromUserId是', this.globalData.FromUserId);
@@ -59,7 +62,7 @@
    //第一次登陆
    this.getSessionID();
    await this.getSessionID();
    //获取sessionid并定时刷新
    // if(this.globalData.openID==''){
    //   this.getSession();
@@ -80,7 +83,8 @@
    // })
    // await this.appOnLoad();
    let login = await this.getSession();
    console.log('....>>>>准备发送login.do请求');
    let login = await this.getSession(options);
    console.log('this.globalData.FromOpenId.........',this.globalData.FromOpenId)
      // this.saveReferrerReward();
    if (this.globalData.FromOpenId!=undefined&&this.globalData.FromOpenId!=''&&this.globalData.FromOpenId!=this.globalData.openID){
@@ -97,13 +101,14 @@
  },
  appOnLoad(){
console.log('开始发送setting请求');
    this.getSettings().then((res) => {
      console.log('res.data.isPullUserInfo......', res.data.isPullUserInfo);
      if(res.data.isPullUserInfo){
        console.log(res);
        this.getUserInfo(res);
        // this.getUserInfo(res);
      }
      this.getFromUserIdForRequest().then((res) => {
@@ -116,39 +121,40 @@
      this.getShareMsg();
      //判断用户是否授权  获取用户信息
      wx.getSetting({
        success: res => {
          console.log('getSetting成功数据', res);
          if (res.authSetting['scope.userInfo']) {
            // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
            //this.globalData.isAuthorize = true;
      // //判断用户是否授权  获取用户信息
      // wx.getSetting({
      //   success: res => {
      //     console.log('getSetting成功数据', res);
      //     if (res.authSetting['scope.userInfo']) {
      //       // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
      //       //this.globalData.isAuthorize = true;
            // console.log(res)
            // this.globalData.userInfo = res.authSetting['scope.userInfo']
            wx.getUserInfo({
              success: res => {
                console.log('用户信息是', res.userInfo);
                this.globalData.userInfo = res.userInfo;
                wx.setStorageSync("userInfo", res.userInfo);
      //       // console.log(res)
      //       // this.globalData.userInfo = res.authSetting['scope.userInfo']
      //       wx.getUserInfo({
      //         success: res => {
      //           console.log('用户信息是', res.userInfo);
      //           this.globalData.userInfo = res.userInfo;
      //           wx.setStorageSync("userInfo", res.userInfo);
                this.globalData.messageCallback(res);
                // 发送websocket
                // this.webSocket();
                // this.listeningSocket()
      //           this.globalData.messageCallback(res);
      //           // 发送websocket
      //           // this.webSocket();
      //           // this.listeningSocket()
                // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
                // 所以此处加入 callback 以防止这种情况
                // if (this.userInfoReadyCallback) {
                //   this.userInfoReadyCallback(res);
                // }
              }
            });
          } else {
            //this.globalData.isAuthorize = false;
          }
        }
      });
      //           // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      //           // 所以此处加入 callback 以防止这种情况
      //           // if (this.userInfoReadyCallback) {
      //           //   this.userInfoReadyCallback(res);
      //           // }
      //         }
      //       });
      //     } else {
      //       //this.globalData.isAuthorize = false;
      //     }
      //   }
      // });
      console.log('》》》开始indexCallback');
      this.globalData.indexCallback(res);
      this.globalData.classifyCallback(res);
      this.globalData.idcardCallback(res);
@@ -235,12 +241,26 @@
          this.globalData.isShowPoster = res.data.isShowPoster || '';
          this.globalData.parallelNumberForInnerMenuOnHomePage = res.data.parallelNumberForInnerMenuOnHomePage || 4;
          this.globalData.ProductListStyle = res.data.productListStyle || 0;
          // this.globalData.ProductListStyle = 0;
          this.globalData.isShowPostcode = res.data.isShowPostcode || 0;
          this.globalData.categoryListStyle = res.data.categoryListStyle||0;
          this.globalData.withdrawType = res.data.withdrawType;
          this.globalData.isAllowSelectDeliveryMethod = res.data.isAllowSelectDeliveryMethod||false;
          this.globalData.isShowPreSendDate = res.data.isShowPreSendDate;
          this.globalData.isShowBuyingButton = res.data.isShowBuyingButton;
          this.globalData.deliveryMethod = res.data.deliveryMethod||'';
          this.globalData.isShowBannerPhotoOnHomePageForLiveUser = res.data.isShowBannerPhotoOnHomePageForLiveUser||false;
          this.globalData.isShowMatGroupInHomePage = res.data.isShowMatGroupInHomePage||false;
          this.globalData.startingPointForRedemption = res.data.startingPointForRedemption||0;
          this.globalData.isStartupBalancePay = res.data.isStartupBalancePay||0;
          this.globalData.isModifyOrder = res.data.isModifyOrder||0;
          this.globalData. isModifyWishList = res.data. isModifyWishList||0;
          this.globalData.isModifyReward = res.data.isModifyReward||0;
          this.globalData.isShowMyWallet = res.data.isShowMyWallet||0;
          this.globalData.isModifyAddress = res.data.isModifyAddress||0;
          this.globalData.isShowBuyingButton = res.data.isShowBuyingButton||0;
          this.globalData.isShowElectronicVoucherButton = res.data.isShowElectronicVoucherButton||0;
          this.globalData.showKeFuTelephone = res.data.showKeFuTelephone;
          resolve(res);
        },
@@ -291,7 +311,7 @@
  },
  //获取session
 async getSession() {
 async getSession(options) {
    var that = this;
    // var utils = require('./utils/util')
    let doLogin = (res)=>{
@@ -303,9 +323,12 @@
          },
          data: {
            FromUserId: that.globalData.FromUserId,
            FURID: that.globalData.FURID,
            code: res.code,
            AppId: that.globalData.AppId,
            wx: 3
            wx: 3,
            SceneCode:options?options.scene:'',
            FromOpenId: this.globalData.FromOpenId?this.globalData.FromOpenId:''
          },
          success: function (res) {
            if (res.data['error'] && res.data['error']['warning']) {
@@ -328,13 +351,15 @@
            } else {
              that.globalData.FromUserId = '';
            }
            that.globalData.SessionKey = res.data.SessionKey || '';
            // that.globalData.SessionKey = res.data.SessionKey || '';
            that.globalData.isShopGuide = res.data.isShopGuide || false;
            that.globalData.ReferralsName = res.data.ReferralsName || '';
            that.globalData.UserName = res.data.UserName;
            that.globalData.avatarUrl = res.data.avatarUrl;
            that.globalData.nickName = res.data.nickName;
            that.globalData.tabBarList = res.data.tabBarList;
            that.globalData.KeFuTelephone = res.data.KeFuTelephone;
            // that.globalData.FromUserId = res.data.FromUserId;
            // that.globalData.shopccname = res.data.shopccname;
            console.log('that.globalData.isShopGuide',that.globalData.isShopGuide)
            resolve(res);
@@ -434,39 +459,43 @@
  },
  // 第一次登录
  getSessionID: function () {
  async getSessionID () {
    // let utils = require('./utils/util')
    wx.request({
      url: this.globalData.reqBase + '/wx/miniapp/user/getSessionId.do',
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      data: {
        AppId: this.globalData.AppId,
        wx: 3
      },
      success: res => {
        if (res.data['error'] && res.data['error']['warning']) {
    return new Promise((resolve,reject)=>{
      wx.request({
        url: this.globalData.reqBase + '/wx/miniapp/user/getSessionId.do',
        header: {
          "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
        },
        data: {
          AppId: this.globalData.AppId,
          wx: 3
        },
        success: res => {
          if (res.data['error'] && res.data['error']['warning']) {
            wx.showModal({
              title: '提示',
              content: res.data['error']['warning'],
              showCancel: false
            });
            return false;
          }
          let data = res.data;
          console.log('第一次登录sessionID', res);
          wx.setStorageSync("sessionID", data.JSESSIONID);
          resolve(res);
        },
        fail: function (errmsg) {
          console.log('/wx/miniapp/user/getSessionId.do', errmsg);
          wx.showModal({
            title: '提示',
            content: res.data['error']['warning'],
            title: '/wx/miniapp/user/getSessionId.do',
            content: errmsg.errMsg,
            showCancel: false
          });
          return false;
          reject(errmsg);
        }
        let data = res.data;
        console.log('第一次登录sessionID', res);
        wx.setStorageSync("sessionID", data.JSESSIONID);
      },
      fail: function (errmsg) {
        console.log('/wx/miniapp/user/getSessionId.do', errmsg);
        wx.showModal({
          title: '/wx/miniapp/user/getSessionId.do',
          content: errmsg.errMsg,
          showCancel: false
        });
      }
    });
      });
    })
  },
  getShareMsg(){
@@ -564,46 +593,46 @@
  },
  //
  getUserInfo(res){
    // 必须是在用户已经授权的情况下调用
    wx.getUserInfo({
  // getUserInfo(res){
  //   // 必须是在用户已经授权的情况下调用
  //   wx.getUserInfo({
      success: res => {
        console.log('getUserInfo',res);
        // 把用户信息发送到后台
        wx.request({
          url: this.globalData.reqBase + '/wx/miniapp/user/info.do',
          header: {
            "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
          },
          data: {
            FromUserId: this.globalData.FromUserId,
            AppId: this.globalData.AppId,
            wx: 3,
            signature: res.signature,
            rawData: res.rawData,
            encryptedData: res.encryptedData,
            iv: res.iv,
            SessionKey: this.globalData.SessionKey
          },
          success: (res) => {
            if (res.data['error'] && res.data['error']['warning']) {
              wx.showModal({
                title: '提示',
                content: res.data['error']['warning'],
                showCancel: false
              });
              return false;
            }
  //     success: res => {
  //       console.log('getUserInfo',res);
  //       // 把用户信息发送到后台
  //       wx.request({
  //         url: this.globalData.reqBase + '/wx/miniapp/user/info.do',
  //         header: {
  //           "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
  //         },
  //         data: {
  //           FromUserId: this.globalData.FromUserId,
  //           AppId: this.globalData.AppId,
  //           wx: 3,
  //           signature: res.signature,
  //           rawData: res.rawData,
  //           encryptedData: res.encryptedData,
  //           iv: res.iv,
  //           // SessionKey: this.globalData.SessionKey
  //         },
  //         success: (res) => {
  //           if (res.data['error'] && res.data['error']['warning']) {
  //             wx.showModal({
  //               title: '提示',
  //               content: res.data['error']['warning'],
  //               showCancel: false
  //             });
  //             return false;
  //           }
          },
          fail: function (errmsg) {
            this.requestFail(errmsg, '/wx/miniapp/user/info.do');
          }
        })
      }
    })
  },
  //         },
  //         fail: function (errmsg) {
  //           this.requestFail(errmsg, '/wx/miniapp/user/info.do');
  //         }
  //       })
  //     }
  //   })
  // },
  // 解析启动时的url
@@ -630,7 +659,8 @@
  // 获取scene内的参数
 getFromUserId(options) {
    let FromUserId;
    let FromUserId = '';
    let FURID = '';
    // 从url直接取值
    // if ((!FromUserId || FromUserId == '') && options.scene) {
@@ -642,8 +672,10 @@
      let params = this.getUrlkey(decodeURIComponent(options.query.scene));
        FromUserId = params.FromUserId || options.query.FromUserId;
        FURID = params.FURID || options.query.FURID;
        let roomid = params.roomid || options.query.roomid;
        console.log('扫码进入小程序, 地址上的FromUserId为',FromUserId );
        console.log('扫码进入小程序, 地址上的FRUID为',FURID );
        if (roomid) {
          console.log('扫码进入小程序直播间, 地址上的roomid为',roomid,',FromUserId为',FromUserId );
          let customParams = encodeURIComponent(JSON.stringify({
@@ -680,11 +712,15 @@
    }
    // 其他场景进入直接读取参数
    if(!FromUserId){
      FromUserId = options.query.FromUserId;
    }
    if (!FURID) {
      FURID = options.query.FURID;
    }
    return FromUserId;
    return {FromUserId,FURID};
  },
  // 获取scene内的参数
@@ -735,8 +771,12 @@
    // })
    console.log('发生了小程序app onShow事件', options);
    if (!this.isFirstOpenApp) {
      this.getSession();
      this.getSession(options);
      console.log('小程序非初次加载进入onShow,重新login一次');
      if (options.query.FromOpenId) {
        this.globalData.FromOpenId = options.query.FromOpenId;
        console.log('...小程序非初次加载进入onShow,FromOpenId更新为链接中的值 ',this.globalData.FromOpenId);
      }
      // return;
    }
@@ -760,7 +800,7 @@
    }
    // 不是初次打开
    else if(!this.isFirstOpenApp){
      let FromUserId = this.getFromUserId(options);
      let {FromUserId} = this.getFromUserId(options);
      this.handleFromUserIdChange(FromUserId);
    }
@@ -778,7 +818,7 @@
        this.globalData.openID = '';
        this.globalData.FromUserId = this.globalData.tempFromUserId;
        console.log('小程序app onshow 事件发生时 两个FromUserId不相等', this.globalData.FromUserId);
        this.getSession().then(()=>{
        this.getSession(options).then(()=>{
          // this.websocketReconnect();
          // this.getFromUserIdForRequest();
          // this.getSettings();
@@ -911,6 +951,7 @@
  globalData: {
    FURID:'', // 二维码专用的临时FromUserId
    URID:'',
    ReferrerOpenId: '',
    SessionKey: '',