Parcourir la source

add kaisinuojy channel to zy

dong il y a 1 an
Parent
commit
1419925b49

+ 13 - 0
data/config/zy/refill.ini.php

@@ -103,6 +103,18 @@ $renyueoil_oil = ['name' => 'renyueoil', 'store_id' => 113, 'qualitys' => '5',
     'refill_type' => 'api'];
 
 
+$kaisinuojy_oil = ['name' => 'kaisinuojy', 'store_id' => 117, 'qualitys' => '5',
+    'amount' => [
+        50 => [['goods_id' => 7235, 'price' => 50, 'quality' => 5, 'card_type' => 'petrochina,sinopec']],
+        100 => [['goods_id' => 7236, 'price' => 100, 'quality' => 5, 'card_type' => 'petrochina,sinopec']],
+        200 => [['goods_id' => 7237, 'price' => 200, 'quality' => 5, 'card_type' => 'petrochina,sinopec']],
+        500 => [['goods_id' => 7238, 'price' => 500, 'quality' => 5, 'card_type' => 'petrochina,sinopec']],
+        1000 => [['goods_id' => 7239, 'price' => 1000, 'quality' => 5, 'card_type' => 'petrochina,sinopec']],
+//        2000 => [['goods_id' => 7038, 'price' => 2000, 'quality' => 5, 'card_type' => 'petrochina,sinopec']]
+    ],
+    'refill_type' => 'api'];
+
+
 
 $oil_providers = [
     ['name' => 'ruidongsoil', 'cfg' => $ruidongsoil_oil],
@@ -112,6 +124,7 @@ $oil_providers = [
     ['name' => 'qudaiwjiayou', 'cfg' => $qudaiwjiayou_oil],
     ['name' => 'xindejiayou', 'cfg' => $xindejiayou_oil],
     ['name' => 'renyueoil_oil', 'cfg' => $renyueoil_oil],
+    ['name' => 'kaisinuojy', 'cfg' => $kaisinuojy_oil],
 ];
 $config['oil_providers'] = $oil_providers;
 

+ 76 - 0
helper/refill/api/zy/kaisinuojy/RefillCallBack.php

@@ -0,0 +1,76 @@
+<?php
+namespace refill\kaisinuojy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/kaisinuojy/config.php');
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['sign']);
+        $sign = $this->sign($input);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+        return md5($body);
+    }
+
+    public function notify($params)
+    {
+        $status = $params['state'];
+        $order_sn = $params['order_sn'];
+        $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false,false];
+        }
+        $order_id = $order_info['order_id'];
+        if ($status === 'SUCCESS') {
+            $data['ch_trade_no'] = $params['trade_no'];
+            $data['official_sn'] = strtolower($params['official_sn']) == 'null' ? '' : $params['official_sn'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 'CANCEL') {
+            Model('refill_order')->edit($order_id, ['ch_trade_no' => $params['trade_no']]);
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 165 - 0
helper/refill/api/zy/kaisinuojy/RefillOil.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace refill\kaisinuojy;
+
+require_once(BASE_HELPER_RAPI_PATH . '/kaisinuojy/config.php');
+
+use refill;
+use Log;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, int $amount, int $card_type, string $order_sn)
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'add';
+        $params['mchid'] = config::MCH_ID;
+        $params['cardno'] = $card_no;
+        $params['amount'] = $amount;
+        $params['order_sn'] = $order_sn;
+        $params['notifyurl'] = config::NOTIFY_URL;
+
+        $card_info = refill\util::read_card($card_no,$card_type);
+        $params['bind_phone'] = $card_info['bind_phone'];
+        return [$params, $card_info];
+    }
+
+    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    {
+        [$params, $card_info] = $this->req_params($card_no, $amount, $card_type, $params['order_sn']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST' , false , [] , $net_errno);
+
+        if (empty($resp)) {
+            return [false, '系统错误', true];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp ,true);
+            if (empty($resp)) {
+                return [false, '系统错误', true];
+            } elseif ($resp['code'] === 200) {
+                refill\util::inc_card($card_no,$card_info);
+                return [true, '', false];
+            } else {
+                return [false, $resp['message'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'query';
+        $params['mchid'] = config::MCH_ID;
+        $params['order_sn'] = $refill_info['order_sn'];
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST');
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            }
+            elseif ($resp['code'] === 200)
+            {
+                $data = $resp['datas'];
+                if ($data['order_state'] == '40') {
+                    $save['ch_trade_no'] = $data['trade_no'];
+                    $save['official_sn'] = strtolower($resp['official_sn']) == 'null' ? '' : $resp['official_sn'];
+                    Model('refill_order')->edit($refill_info['order_id'], $save);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($data['order_state'] === '0') {
+                    Model('refill_order')->edit($refill_info['order_id'], ['ch_trade_no' => $data['trade_no']]);
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif (in_array($data['order_state'], ['10', '20', '30', '50'], true)) {
+                    $order_state = ORDER_STATE_SEND;
+                } else {
+                    return [false, $resp['message']];
+                }
+                return [true, $order_state];
+            }
+            elseif ($resp['code'] === 202 && (time() - $refill_info['commit_time'] >= 600))
+            {
+                return [true, ORDER_STATE_NOEXIST];
+            }
+            else
+            {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['act'] = 'refill';
+        $params['op'] = 'balance';
+        $params['mchid'] = config::MCH_ID;
+        $params['sign'] = $this->sign($params);
+
+        $resp = http_request(config::ORDER_URL, $params , 'POST');
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['code'] === 200) {
+                return [true, $resp['datas']['balance']];
+            } else {
+                return [false, $resp['message']];
+            }
+        }
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        ksort($params);
+
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+
+        $body .= "&key=".config::KEY;
+
+        return md5($body);
+    }
+}

+ 7 - 0
helper/refill/api/zy/kaisinuojy/api.txt

@@ -0,0 +1,7 @@
+https://admin.xyzshops.cn/merchant/#/login
+
+xindejiayou
+dfxd3_jkjx
+
+10455
+faff9d8ca5e07c0e5192d7fca70f45ea

+ 13 - 0
helper/refill/api/zy/kaisinuojy/config.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace refill\kaisinuojy;
+
+class config
+{
+    const ORDER_URL = 'https://www.xyzshops.cn/mobile/index.php';
+
+    const MCH_ID = 10482;
+    const KEY = '2cad24fa530e5ebef5b850b4515627f1';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_kaisinuojy.php";
+
+}

+ 4 - 0
mobile/callback/refill_kaisinuojy.php

@@ -0,0 +1,4 @@
+<?php
+
+refill\util::push_notify('kaisinuojy',$_POST);
+echo ('SUCCESS');

+ 13 - 0
test/TestRefill.php

@@ -5434,6 +5434,19 @@ class TestRefill extends TestCase
             'product_code' => 'XYZ100747'
         ]);
     }
+
+
+    public function testKaisinuojy_Balance()
+    {
+        $provider = $this->getProvider('kaisinuojy', 'RefillOil');
+        [$succ, $val] = $provider->balance();
+    }
+
+    public function testKaisinuojy_Add()
+    {
+        $provider = $this->getProvider('kaisinuojy', 'RefillOil');
+        $resp = $provider->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
+    }
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test