From 9617d4a95093be4d25572d398c434a7746716f3f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 09 七月 2022 22:45:34 +0800
Subject: [PATCH] 2022-07-09

---
 src/api/index.js |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 10a19bd..24695e0 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -110,23 +110,29 @@
   /**
    * @description 寰俊涓氬姟璇锋眰
    */
-  wxRequest (url, method, param) {
-    let _url = document.location.origin + '/' + window.GLOB.service + url
+  wxAccessToken () {
+    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/getaccesstoken'
     if (process.env.NODE_ENV !== 'production') {
-      _url = document.location.origin + '/' + url
+      _url = document.location.origin + '/wxpay/getaccesstoken'
     }
 
-    if (param) {
-      return axios({
-        url: _url,
-        method,
-        data: param
-      })
-    }
-
-    return axios({
-      url: _url,
-      method
+    return new Promise(resolve => {
+      if (window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) {
+        resolve(window.GLOB.accessToken)
+      } else {
+        window.GLOB.accessToken = {}
+        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)
+        })
+      }
     })
   }
 
@@ -224,7 +230,6 @@
 
     let url = '/webapi/dologon/s_visitor_login'
     if (window.GLOB.mainSystemApi) {
-      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
       param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
     }
 
@@ -259,14 +264,12 @@
     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')
     }
 

--
Gitblit v1.8.0