Browse Source

椰子-添加乐友(油费)通道

zhaoming 1 năm trước cách đây
mục cha
commit
30046c5a22
3 tập tin đã thay đổi với 66 bổ sung33 xóa
  1. 30 0
      data/config/xyz/refill.ini.php
  2. 22 33
      helper/refill/api/xyz/leyou/RefillOil.php
  3. 14 0
      test/TestRefill.php

+ 30 - 0
data/config/xyz/refill.ini.php

@@ -328,6 +328,35 @@ $xinma_oil = ['name' => 'xinma', 'store_id' => 339, 'qualitys' => '5',
     ],
     'period' => [], 'refill_type' => 'api'];
 
+$leyou_oil = ['name' => 'leyou', 'store_id' => 358, 'qualitys' => '5',
+    'amount' => [
+        50 => [
+            ['goods_id' => 8860, 'price' => 50.15, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8860, 'price' => 10.12, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+        100 => [
+            ['goods_id' => 8854, 'price' => 100.3, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8854, 'price' => 100.6, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+        200 => [
+            ['goods_id' => 8855, 'price' => 200.6, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8855, 'price' => 201.2, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+        500 => [
+            ['goods_id' => 8856, 'price' => 501.5, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8856, 'price' => 502, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+        1000 => [
+            ['goods_id' => 8857, 'price' => 1003, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8857, 'price' => 1004, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+        2000 => [
+            ['goods_id' => 8861, 'price' => 2006, 'quality' => 5, 'card_type' => 'petrochina'],
+            ['goods_id' => 8861, 'price' => 2008, 'quality' => 5, 'card_type' => 'sinopec'],
+        ],
+    ],
+    'period' => [], 'refill_type' => 'api'];
+
 $oil_providers = [
 //    ['name' => 'tianjt', 'cfg' => $tianjt_oil],
 //    ['name' => 'suhctm', 'cfg' => $suhctm_oil],
@@ -353,6 +382,7 @@ $oil_providers = [
     ['name' => 'zhongst_oil', 'cfg' => $zhongst_oil],
     ['name' => 'quanzhen', 'cfg' => $quanzhen_oil],
     ['name' => 'xinma', 'cfg' => $xinma_oil],
+    ['name' => 'leyou', 'cfg' => $leyou_oil],
 ];
 $config['oil_providers'] = $oil_providers;
 

+ 22 - 33
helper/refill/api/xyz/leyou/RefillOil.php

@@ -59,25 +59,19 @@ class RefillOil extends refill\IRefillOil
             }
             elseif (in_array($status,[122610,122616])) { //manual handle
                 $net_errno = "HTTP-$status";
-                return [false, $resp['reason'], true];
+                return [false, $resp['data'], true];
             }
             else { //error
-                return [false, $resp['reason'], false];
+                return [false, $resp['data'], false];
             }
         }
     }
 
     public function query($refill_info)
     {
-        $open_id = config::OPEN_ID;
-        $key = config::APP_KEY;
-
-        $params['key'] = $key;
-        $params['order_id'] = $refill_info['order_sn'];
-        $params['timestamp'] = time();
-
-        $content = "{$open_id}{$key}{$params['order_id']}{$params['timestamp']}";
-        $params['sign'] = md5($content);
+        $params['username'] = config::USER_NAME;
+        $params['orderNumber'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
 
         $resp = http_request(config::QUERY_URL, $params, 'POST', false, config::ExtHeaders);
         if (empty($resp)) {
@@ -86,32 +80,25 @@ class RefillOil extends refill\IRefillOil
         else
         {
             Log::record($resp, Log::DEBUG);
+
             $resp = json_decode($resp, true);
             if (empty($resp)) {
                 return [false, '网络错误'];
             }
-            elseif ($resp['error_code'] === 0)
-            {
-                $status = $resp['result']['status'];
-                if ($status === '1') {
-                    $order_state = ORDER_STATE_SUCCESS;
-                } elseif ($status === '9') {
-                    $order_state = ORDER_STATE_CANCEL;
-                } elseif ($status === '0') {
-                    $order_state = ORDER_STATE_SEND;
-                } else {
-                    return [false, $status];
-                }
-
-                return [true, $order_state];
+
+            $status = $resp['status'];
+
+            if ($status === 122600) {
+                $order_state = ORDER_STATE_SUCCESS;
             }
-            elseif ($resp['error_code'] === 208712 && (time() - $refill_info['commit_time'] > 600))
-            {
-                return [true, ORDER_STATE_NOEXIST];
+            elseif ($status === 122617) {
+                $order_state = ORDER_STATE_NOEXIST;
             }
             else {
-                return [false, $resp['reason']];
+                return [false, $status];
             }
+            return [true, $order_state];
+
         }
     }
 
@@ -132,10 +119,12 @@ class RefillOil extends refill\IRefillOil
             $resp = json_decode($resp, true);
             if (empty($resp)) {
                 return [false, '系统错误'];
-            } elseif ($resp['error_code'] === 0) {
-                return [true, $resp['result']['balance']];
-            } else {
-                return [false, $resp['reason']];
+            }
+            elseif ($resp['status'] === 122600) {
+                return [true, $resp['data']];
+            }
+            else {
+                return [false, $resp['desc']];
             }
         }
     }

+ 14 - 0
test/TestRefill.php

@@ -5331,6 +5331,20 @@ class TestRefill extends TestCase
         [$succ, $val] = $provider->balance();
     }
 
+    public function testLeyou_Add()
+    {
+        $provider = $this->getProvider('leyou','RefillOil');
+        $net_errno = '';
+        [$succ, $val, $neterr] = $provider->add('1000111100021211884', 2, 50, ['order_sn'=>'Test-Leyou-Oil'.time()], $net_errno);
+    }
+
+    public function testLeyou_Query()
+    {
+        $provider = $this->getProvider('leyou','RefillOil');
+        $net_errno = '';
+        [$succ, $val] = $provider->query(['order_sn'=>'Test-Leyou-Oil1693375143']);
+    }
+
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test