From 58826d6f4eab9f8c9acf9fa8696f60039c645cfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 20 八月 2024 18:18:00 +0800
Subject: [PATCH] 2024-08-20

---
 src/api/index.js |  211 +++++++++++++++++++++++++++-------------------------
 1 files changed, 108 insertions(+), 103 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index bd49113..b24fd12 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -15,7 +15,8 @@
 window.GLOB.$error = false
 
 let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : ''
-let db = `mkdb${service}`
+let lang = sessionStorage.getItem('lang') !== 'zh-CN' ? sessionStorage.getItem('lang') : ''
+let db = `mkdb${service + lang}`
 
 if (window.indexedDB) {
   CacheUtils.openIndexDB(db)
@@ -97,37 +98,21 @@
   }
 
   /**
-   * @description 寰俊涓氬姟璇锋眰
+   * @description 寰俊涓氬姟璇锋眰 鍘熸帴鍙� 'wxpay/getaccesstoken'
    */
-  wxAccessToken (domain = '') {
-    let _url = window.GLOB.baseurl + 'wxpay/getaccesstoken'
+  // wxAccessToken (appId, domain = '') {
+  //   let _url = domain || window.GLOB.baseurl
 
-    if (domain) {
-      _url = domain + 'wxpay/getaccesstoken'
-    }
-
-    return new Promise(resolve => {
-      if (window.GLOB.accessToken.domain === domain && window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) {
-        resolve(window.GLOB.accessToken)
-      } else {
-        window.GLOB.accessToken = {domain}
-        axios({
-          url: _url,
-          method: 'get'
-        }).then(res => {
-          if (res.oa_access_token || res.mini_access_token) {
-            window.GLOB.accessToken.accessTime = parseInt(new Date().getTime() / 1000)
-            window.GLOB.accessToken.oa_access_token = res.oa_access_token
-            window.GLOB.accessToken.mini_access_token = res.mini_access_token
-          }
-          resolve(res)
-        })
-      }
-    })
-  }
+  //   return axios({
+  //     url: _url + 'wechat/getaccesstoken',
+  //     method: 'post',
+  //     data: JSON.stringify({app_id: appId})
+  //   })
+  // }
 
   /**
    * @description 寰俊涓氬姟璇锋眰
+   * 39涓� qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn
    */
   wxNginxRequest (url, method, param) {
     let _url = url
@@ -137,17 +122,12 @@
       if (process.env.NODE_ENV === 'production') {
         _url = document.location.origin + '/' + url
       }
-      if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-        _url = window.GLOB.location + ':8080/' + url
-        if (process.env.NODE_ENV === 'production') {
-          _url = document.location.origin + ':8080/' + url
-        }
-      } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-        _url = window.GLOB.location + ':8443/' + url
-        if (process.env.NODE_ENV === 'production') {
-          _url = document.location.origin + ':8443/' + url
-        }
-      }
+    }
+    if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) {
+      _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/')
+      _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/')
+      _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/')
+      _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/')
     }
     
     if (param) {
@@ -167,7 +147,27 @@
   /**
    * @description 鐩存帴璇锋眰
    */
-  directRequest (params) {
+  directRequest (params, script, position) {
+    if (script) {
+      try {
+        // eslint-disable-next-line
+        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', 'notification', script)
+        let promise = func(axios, this, params, position, window.GLOB.systemType, notification)
+
+        if (promise instanceof Promise) {
+          return promise
+        }
+      } catch (e) {
+        console.warn(e)
+      }
+
+      return Promise.resolve({
+        status: false,
+        message: '鑷畾涔夎剼鏈墽琛岄敊璇�',
+        ErrCode: 'E'
+      })
+    }
+    
     return axios(params)
   }
 
@@ -492,26 +492,26 @@
   /**
    * @description 鑾峰彇鎴栦慨鏀圭郴缁熼厤缃紝澧炲姞appkey
    */
-  getSystemFuncs (time) {
-    let param = {
-      func: 's_get_func_base_sso',
-      update_date: time,
-      userid: sessionStorage.getItem('UserID') || '',
-      lang: sessionStorage.getItem('lang') || '',
-      SessionUid: localStorage.getItem('SessionUid') || '',
-      LoginUID: sessionStorage.getItem('LoginUID') || '',
-      appkey: window.GLOB.appkey
-    }
+  // getSystemFuncs (time) {
+  //   let param = {
+  //     func: 's_get_func_base_sso',
+  //     update_date: time,
+  //     userid: sessionStorage.getItem('UserID') || '',
+  //     lang: sessionStorage.getItem('lang') || '',
+  //     SessionUid: localStorage.getItem('SessionUid') || '',
+  //     LoginUID: sessionStorage.getItem('LoginUID') || '',
+  //     appkey: window.GLOB.appkey
+  //   }
 
-    let url = window.GLOB.mainSystemApi || '/webapi/dostars'
-    param = this.encryptParam(param)
+  //   let url = window.GLOB.mainSystemApi || '/webapi/dostars'
+  //   param = this.encryptParam(param)
 
-    return axios({
-      url: `${url}/${param.func}`,
-      method: 'post',
-      data: JSON.stringify(param)
-    })
-  }
+  //   return axios({
+  //     url: `${url}/${param.func}`,
+  //     method: 'post',
+  //     data: JSON.stringify(param)
+  //   })
+  // }
 
   /**
    * @description 鑾峰彇鎴栦慨鏀圭郴缁熼厤缃紝澧炲姞appkey
@@ -865,8 +865,8 @@
     if (script) {
       try {
         // eslint-disable-next-line
-        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', script)
-        let promise = func(axios, this, param, position, window.GLOB.systemType)
+        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', 'notification', script)
+        let promise = func(axios, this, param, position, window.GLOB.systemType, notification)
 
         if (promise instanceof Promise) {
           return promise
@@ -940,7 +940,7 @@
       })
     } else {
       let url = '/webapi/dostars'
-      if (param.rduri && !window.GLOB.transfer && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
+      if (param.rduri && (!window.GLOB.transfer || /https:\/\/sso.mk9h.cn/.test(param.rduri)) && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
         url = param.rduri
         delete param.rduri
       }
@@ -999,26 +999,45 @@
   /**
    * @description 澶ф枃浠朵笂浼�
    */
-  getLargeFileUpload (param) {
-    return axios({
-      url: '/webapi/doupload',
-      method: 'post',
-      headers: { 'Content-Type': 'multipart/form-data' },
-      data: param
+  getFileUpload (param) {
+    param.append('shardingCnt', 1)
+    param.append('LoginUID', sessionStorage.getItem('LoginUID') || '')
+    param.append('UserID', sessionStorage.getItem('UserID') || '')
+
+    return new Promise((resolve, reject) => {
+      axios({
+        url: '/webapi/doupload',
+        method: 'post',
+        headers: { 'Content-Type': 'multipart/form-data' },
+        data: param
+      }).then(res => {
+        if (res.status && res.urlPath) {
+          if (!/Content\/images/.test(res.urlPath)) {
+            let key = CryptoJS.enc.Utf8.parse('D1185ED7B32568C9')
+            let wordArray = CryptoJS.enc.Base64.parse(res.urlPath)
+            let decryptedWordArray = CryptoJS.AES.decrypt({ ciphertext: wordArray }, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
+            res.urlPath = CryptoJS.enc.Utf8.stringify(decryptedWordArray)
+          }
+          if (!/^http/.test(res.urlPath)) {
+            res.urlPath = window.GLOB.baseurl + res.urlPath
+          }
+        }
+        resolve(res)
+      })
     })
   }
 
   /**
    * @description 鏌ヨ鏂囦欢鏄惁宸蹭笂浼�
    */
-  getFilePreUpload (param) {
-    return axios({
-      url: '/webapi/dopreload',
-      method: 'post',
-      headers: { 'Content-Type': 'multipart/form-data' },
-      data: param
-    })
-  }
+  // getFilePreUpload (param) {
+  //   return axios({
+  //     url: '/webapi/dopreload',
+  //     method: 'post',
+  //     headers: { 'Content-Type': 'multipart/form-data' },
+  //     data: param
+  //   })
+  // }
 
   /**
    * @description oss鏂囦欢涓婁紶
@@ -1028,16 +1047,11 @@
     if (process.env.NODE_ENV === 'production') {
       _url = document.location.origin + '/file/oss/upload'
     }
-    if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-      _url = window.GLOB.location + ':8080/file/oss/upload'
-      if (process.env.NODE_ENV === 'production') {
-        _url = document.location.origin + ':8080/file/oss/upload'
-      }
-    } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-      _url = window.GLOB.location + ':8443/file/oss/upload'
-      if (process.env.NODE_ENV === 'production') {
-        _url = document.location.origin + ':8443/file/oss/upload'
-      }
+    if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) {
+      _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/')
+      _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/')
+      _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/')
+      _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/')
     }
     
     return axios({
@@ -1049,30 +1063,24 @@
   }
 
   /**
-   * @description 鑾峰彇寰俊鏀粯浜岀淮鐮�
+   * @description 鑾峰彇寰俊鏀粯浜岀淮鐮� 鍘熸帴鍙xpay/wxNativePay
    */
   getWxNativePay (param) {
-    let _url = window.GLOB.baseurl + 'wxpay/wxNativePay'
-
     return axios({
-      url: _url,
+      url: window.GLOB.baseurl + 'wechat/native',
       method: 'post',
-      data: qs.stringify(param)
+      data: JSON.stringify(param)
     })
   }
 
   /**
-   * @description 寰俊鏀粯閫�娆�
+   * @description 寰俊鏀粯閫�娆� 鍘熸帴鍙xpay/wxRefund
    */
-  setRefund (orderId) {
-    let _param = new FormData()
-    _param.append('out_biz_no', orderId)
-
+  setRefund (param) {
     return axios({
-      url: '/wxpay/wxRefund',
-      headers: { 'Content-Type': 'multipart/form-data' },
+      url: window.GLOB.baseurl + 'wechat/wxRefund',
       method: 'post',
-      data: _param
+      data: JSON.stringify(param)
     })
   }
 
@@ -1087,7 +1095,7 @@
   /**
    * @description sql妫�楠�
    */
-  sDebug (sql, rduri = null) {
+  sDebug (sql) {
     let param = {
       func: 's_debug_sql',
       exec_type: window.GLOB.execType || 'y',
@@ -1106,13 +1114,14 @@
     sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid')}'`)
     sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID')}'`)
     sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey}'`)
+    sql = sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
     // sql = sql.replace(/@datam@/ig, `''`)
 
     if (window.GLOB.externalDatabase !== null) {
       sql = sql.replace(/@db@/ig, window.GLOB.externalDatabase)
     }
 
-    console.info(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`)
+    window.mkInfo(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`)
 
     sql = sql.replace(/\n/ig, ' ')
 
@@ -1122,10 +1131,6 @@
     param = this.encryptParam(param)
 
     let url = '/webapi/dostars'
-
-    if (rduri) {
-      url = rduri
-    }
 
     let timer = setTimeout(() => {
       let _param = {

--
Gitblit v1.8.0