stanley-king %!s(int64=2) %!d(string=hai) anos
pai
achega
16f2651800

+ 16 - 11
crontab/control/vender.php

@@ -8,8 +8,7 @@ require_once(BASE_HELPER_PATH . '/refill/divert_account.php');
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_CORE_PATH . '/framework/function/http.php');
 require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
-require_once(BASE_HELPER_PATH . '/task/task_helper.php');
-require_once(BASE_HELPER_RAPI_PATH . "/gdsinopec/RefillOil.php");
+
 
 class vendorControl
 {
@@ -20,9 +19,22 @@ class vendorControl
     //中石化电子券token获取
     public function token_refreshOp()
     {
-        $worker = function () : bool {
+        Log::record(__METHOD__,Log::DEBUG);
+        require_once(BASE_HELPER_RAPI_PATH . "/gdsinopec/config.php");
 
-            return true;
+        $worker = function () : bool
+        {
+            $token_req = new refill\gdsinopec\config();
+            [$state, $result] = $token_req->get_access_token();
+            if ($state === false) {
+                Log::record("get token fail msg:$result", Log::ERR);
+                return false;
+            } else {
+                $access_token = $result['access_token'];
+                $expires_in = intval($result['expires_in']);
+                wcache('vendor-cfgs', ['gdsinopec-token' => $access_token,'gdsinopec-time' => time() + $expires_in],'refill-');
+                return true;
+            }
         };
 
         $next_time = 0;
@@ -36,13 +48,6 @@ class vendorControl
                     sleep(1);
                 }
                 elseif($worker()) {
-                    $provider = new refill\gdsinopec\RefillOil([]);
-                    [$state, $access_token] = $provider->get_access_token();
-                    if($state === false) {
-                        Log::record("get token fail msg:{$access_token}",Log::ERR);
-                    }else{
-
-                    }
                     $next_time = time() + $period;
                 }
                 else {

+ 13 - 0
docker/compose/stanley/vendor/docker-compose.yml

@@ -0,0 +1,13 @@
+version: "3.7"
+
+services:
+  token_refresh:
+    image: php-zts-debug:7.3.18
+    volumes:
+      - ../../../../:/var/www/html
+      - ../conf/etc/localtime:/etc/localtime:ro
+      - ../conf/php/php-debug.ini:/usr/local/etc/php/php.ini
+      - /Volumes/Transcend/upload:/var/www/html/data/upload
+      - /Users/stanley-king/work/PHPProject/shoplog:/var/www/html/data/log
+    container_name: "panda-token-refresh"
+    command: [php,"/var/www/html/crontab/index.php",'vendor','token_refresh']

+ 1 - 18
helper/refill/api/xyz/gdsinopec/RefillOil.php

@@ -16,25 +16,8 @@ class RefillOil extends refill\IRefillOil
         parent::__construct($cfgs);
     }
 
-    public function get_access_token()
-    {
-        $params['appid'] = config::APP_ID;
-        $params['secret'] = config::APP_SECRET;
+    private function token() {
 
-        $resp = http_request(config::TOKEN_URL, $params, 'GET', false, config::ExtHeaders, $net_errno);
-        if (empty($resp)) {
-            return [false, '网络错误'];
-        } else {
-            Log::record($resp, Log::DEBUG);
-            $resp = json_decode($resp, true);
-            if (empty($resp)) {
-                return [false, '网络错误'];
-            } elseif ($resp['state'] === 'ok') {
-                return [true, $resp['data']['access_token']];
-            } else {
-                return [false, $resp['info']];
-            }
-        }
     }
 
     public function get_supplier($access_token)

+ 29 - 0
helper/refill/api/xyz/gdsinopec/config.php

@@ -2,6 +2,8 @@
 
 namespace refill\gdsinopec;
 
+use Log;
+
 class config
 {
     const TOKEN_URL = 'http://dev.tetong.9aijoy.com/open/api/token'; //获取AccessToken
@@ -15,4 +17,31 @@ class config
     const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_sinopec.php";
     const ExtHeaders = ['Content-Type:application/x-www-form-urlencoded;charset=utf-8'];
     const PAGE_SIZE = 200;
+
+
+    public function get_access_token()
+    {
+        $params['appid'] = config::APP_ID;
+        $params['secret'] = config::APP_SECRET;
+
+        $resp = http_request(config::TOKEN_URL, $params, 'GET', false, config::ExtHeaders, $net_errno);
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        } else {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '网络错误'];
+            } elseif ($resp['state'] === 'ok') {
+                return [true, $resp['data']];
+            } else {
+                return [false, $resp['info']];
+            }
+        }
+    }
+
+    public static function token()
+    {
+        rcache();
+    }
 }