From 8e8f505f37ecc4e6945e7d0d6e9883e4e9352437 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 十一月 2022 23:59:47 +0800
Subject: [PATCH] 2022-11-10

---
 src/api/index.js |  119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 3270525..2623ef3 100644
--- a/src/api/index.js
+++ b/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,
@@ -827,6 +829,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: '鎺ュ彛淇℃伅瑙f瀽澶辫触锛�'})
+    }
+
+    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: localStorage.getItem('SessionUid')
+      }
+  
+      _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+
+      _param.Type = token.publicKey
+      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)
+      _param.appkey = token.appkey || ''
+      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'鎴栦簯绔椂锛屼紶鍏serid銆丩oginUID
@@ -838,6 +951,12 @@
     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') {
         param.username = sessionStorage.getItem('CloudUserName') || ''

--
Gitblit v1.8.0