king
2022-12-06 91e232bb0b910f3670bdbccd65cc218d55e1eda9
src/api/index.js
@@ -2,6 +2,7 @@
import qs from 'qs'
import { notification } from 'antd'
import md5 from 'md5'
import CryptoJS from 'crypto-js'
import jsSHA from 'jssha'
import moment from 'moment'
import Utils from '@/utils/utils.js'
@@ -10,6 +11,7 @@
window.GLOB.WebSql = null
window.GLOB.IndexDB = null
window.GLOB.OuterToken = {}
const systemMenuKeys = `1581067625930haged11ieaivpavv77k,1581734956310scks442ul2d955g9tu5,1583991994144ndddg0bhh0is6shi0v1,1583979633842550imkchl4qt4qppsiv,1578900109100np8aqd0a77q3na46oas,
  1585192949946f3et2ts8tn82krmumdf,15855615451212m12ip23vpcm79kloro,1587005717541lov40vg61q7l1rbveon,1590458676585agbbr63t6ihighg2i1g,1602315375262ikd33ii0nii34pt861o,1582771068837vsv54a089lgp45migbg,
  1582777675954ifu05upurs465omoth7,158294809668898cklbv6c5bou8e1fpu,1584676379094iktph45fb8imhg96bql,1584695125339vo5g7iqgfn01qmrd6s2,1584699661372vhmpp9dn9foo0eob722,15848421131551gg04ie8sitsd3f7467,
@@ -30,7 +32,7 @@
axios.defaults.withCredentials = false
axios.interceptors.request.use((config) => {
  if (config.url.includes('LoginAndRedirect') || config.url.includes('getjsonresult') || config.url.includes('wxNativePay')) {
  if (/LoginAndRedirect|getjsonresult|wxNativePay|postek/ig.test(config.url)) {
    config.data = qs.stringify(config.data)
  } else if (/\/doupload|\/dopreload|\/upload/.test(config.url)) {
    config.headers = { 'Content-Type': 'multipart/form-data' }
@@ -217,7 +219,8 @@
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), 
      SessionUid: _SessionUid,
      TypeCharOne: 'pc',
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host))
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      appkey: window.GLOB.appkey || ''
    }
    let url = '/webapi/dologon/s_visitor_login'
@@ -251,8 +254,6 @@
    param.v_type = param.v_type || 'Y'
    param.secretkey = md5(param.LText + solt + param.timestamp)
    param.appkey = window.GLOB.appkey || ''
    return axios({
      url: url,
      method: 'post',
@@ -275,10 +276,9 @@
      login_city: city,
      login_id_address: ipAddress,
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid')
      device_id: localStorage.getItem('SessionUid'),
      appkey: window.GLOB.appkey || ''
    }
    param.appkey = window.GLOB.appkey || ''
    let url = '/webapi/dologon'
    if (isCloud) {
@@ -312,10 +312,10 @@
      login_city: city,
      login_id_address: ipAddress,
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid')
      device_id: localStorage.getItem('SessionUid'),
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
      appkey: window.GLOB.appkey || ''
    }
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    let sys_datetime = sessionStorage.getItem('sys_datetime')
    let app_datetime = sessionStorage.getItem('app_datetime')
@@ -340,20 +340,17 @@
    // Type: 'X' 时
    // param.Password = Utils.formatOptions(password)
    param.appkey = window.GLOB.appkey || ''
    let url = '/webapi/dologon'
    if (isCloud) {
      param.debug = 'Y'
      if (options.cloudServiceApi) {
        // url = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
        param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      }
    } else if (window.GLOB.mainSystemApi) {
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        param.linkurl = window.GLOB.linkurl
      }
      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
    }
@@ -800,12 +797,15 @@
      delete param.rduri
    }
    let _param = JSON.parse(JSON.stringify(param)) // 缓存校验,去除时间和加密字符
    delete _param.timestamp
    delete _param.secretkey
    delete _param.open_key
    _param = JSON.stringify(_param)
    _param  = md5(_param)
    let _param = ''
    if (cache) {
      _param = JSON.parse(JSON.stringify(param)) // 缓存校验,去除时间和加密字符
      delete _param.timestamp
      delete _param.secretkey
      delete _param.open_key
      _param = JSON.stringify(_param)
      _param  = md5(_param)
    }
    if (cache && window.GLOB.CacheMap.has(_param)) {
      return Promise.resolve(window.GLOB.CacheMap.get(_param))
@@ -827,6 +827,117 @@
    }
  }
  visitOuterSystem (param, _resolve) {
    let token = param.$token
    delete param.$token
    try {
      token = JSON.parse(token)
      token = token.message
      const key = CryptoJS.enc.Utf8.parse(window.GLOB.appkey.slice(-16))
      const iv = CryptoJS.enc.Utf8.parse('mksoft')
      let encryptedHexStr = CryptoJS.enc.Hex.parse(token)
      let _srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
      let decrypt = CryptoJS.AES.decrypt(_srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
      let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
      token = decryptedStr.toString()
      token = JSON.parse(window.decodeURIComponent(window.atob(token)))
    } catch (e) {
      token = null
      _resolve({status: false, ErrCode: 'E', message: '接口信息解析失败!'})
    }
    if (!token) return
    let userid = ''
    let loginUid = ''
    let dataM = ''
    if (window.GLOB.OuterToken[token.interface]) {
      let msg = window.GLOB.OuterToken[token.interface]
      let seconds = Math.floor((new Date().getTime() - msg.timestamp) / 1000)
      if (seconds >= 3600) {
        delete window.GLOB.OuterToken[token.interface]
      } else {
        userid = msg.userid
        loginUid = msg.loginUid
        dataM = msg.dataM || ''
      }
    }
    // param.appkey = token.appkey || ''
    if (userid && loginUid) {
      param.dataM = dataM
      param.userid = userid
      param.LoginUID = loginUid
      param = this.encryptParam(param)
      axios({
        url: token.interface,
        method: 'post',
        data: param
      }).then(res => {
        _resolve(res)
      })
    } else {
      let _param = {
        UserName: token.username,
        systemType: options.sysType,
        login_city: sessionStorage.getItem('city') || '',
        device_id: token.appkey || '',
        timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
        Type: token.publicKey,
        appkey: token.appkey || ''
      }
      let shaObj = new jsSHA('SHA-1', 'TEXT')
      shaObj.update(token.password)
      _param.Password = shaObj.getHash('HEX').toUpperCase()
      _param.Password = md5(token.privateKey + token.username + _param.Password + _param.timestamp)
      let url = token.interface.replace(/\/webapi(.*)/, '/webapi/dologon')
      if (token.ssoInterface) {
        _param.rduri = token.ssoInterface.replace(/\/webapi(.*)/, '/webapi/dologon')
      }
      axios({
        url,
        method: 'post',
        data: _param
      }).then(result => {
        if (result.status) {
          window.GLOB.OuterToken[token.interface] = {
            userid: result.UserID,
            loginUid: result.LoginUID,
            timestamp: new Date().getTime(),
            dataM: result.dataM ? 'Y' : ''
          }
          param.dataM = result.dataM ? 'Y' : ''
          param.userid = result.UserID
          param.LoginUID = result.LoginUID
          param = this.encryptParam(param)
          axios({
            url: token.interface,
            method: 'post',
            data: param
          }).then(res => {
            _resolve(res)
          })
        } else {
          _resolve(result)
        }
      })
    }
  }
  /**
   * @description 获取业务通用接口
   * 访问 'https://sso.mk9h.cn/webapi/dostars'或云端时,传入userid、LoginUID
@@ -837,6 +948,12 @@
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    if (param.$token === '') {
      return Promise.resolve({status: false, ErrCode: 'E', message: '接口地址尚未设置!'})
    } else if (param.$token) {
      return new Promise(resolve => this.visitOuterSystem(param, resolve))
    }
    if (['sPC_Get_TableData', 'sPC_Get_TableData_debug', 'sPC_TableData_InUpDe', 'sPC_TableData_InUpDe_debug', 'sPC_Get_structured_data'].includes(param.func)) {
      if (sessionStorage.getItem('isEditState') === 'true') {
@@ -1067,6 +1184,14 @@
    })
  }
  postekPrint (data) {
    return axios({
      url: 'http://127.0.0.1:888/postek/print',
      method: 'post',
      data: data
    })
  }
  // /**
  //  * @description 文件上传
  //  */