stanley-king 4 лет назад
Родитель
Сommit
9752105774

+ 12 - 1
data/config/prod/refill.ini.php

@@ -48,13 +48,24 @@ $saihu_oil = ['name' => 'saihu', 'store_id' => 15, 'card_type' => ['sinopec'],
         1000 => ['goods_id' => 6316, 'price' => 970],
         2000 => ['goods_id' => 6317, 'price' => 1940]], 'refill_type' => 'api'];
 
+$gftd_oil = ['name' => 'gftd', 'store_id' => 19, 'card_type' => ['petrochina','sinopec'],
+    'amount' => [
+        100 => ['goods_id' => 6339, 'price' => 95],
+        200 => ['goods_id' => 6340, 'price' => 190],
+        500 => ['goods_id' => 6341, 'price' => 475],
+        1000 => ['goods_id' => 6342, 'price' => 950]
+    ],
+    'period' => [], 'refill_type' => 'api'];
+
 $oil_providers = [
     ['name' => 'suhc', 'cfg' => $suhc_oil, 'opened' => false, 'sort' => 3],
     ['name' => 'suhctm', 'cfg' => $suhctm_oil, 'opened' => true, 'sort' => 1],
     ['name' => 'suhcpdd', 'cfg' => $suhcpdd_oil, 'opened' => true, 'sort' => 2],
     ['name' => 'zzx', 'cfg' => $zzx_oil, 'opened' => false, 'sort' => 5],
     ['name' => 'lx', 'cfg' => $lx_oil, 'opened' => false, 'sort' => 1],
-    ['name' => 'saihu', 'cfg' => $saihu_oil, 'opened' => false, 'sort' => 6]];
+    ['name' => 'saihu', 'cfg' => $saihu_oil, 'opened' => false, 'sort' => 6],
+    ['name' => 'gftd', 'cfg' => $gftd_oil, 'opened' => true, 'sort' => 1]
+    ];
 $config['oil_providers'] = $oil_providers;
 
 $beixt_phone = ['name' => 'beixt', 'store_id' => 8, 'card_type' => ['chinamobile', 'chinaunicom', 'chinatelecom'],

+ 1 - 1
helper/fcgi_server.php

@@ -28,7 +28,7 @@ class fcgi_server
             'wxnotify.php','pub_wxnotify.php','alipay_notify_url.php','dispatch_notify.php','kdniao_notify.php',
             'cmbpay_notify.php','cmbpay_sign.php','wxauthor.php','api/wxLogin/index.php','api/wxLogin/callback.php',
             'signature.php',
-            'refill_suhc.php','refill_suhctm.php','refill_suhcpdd.php',
+            'refill_suhc.php','refill_suhctm.php','refill_suhcpdd.php','refill_gftd.php',
             'refill_beixt.php','refill_bxtwt.php','refill_bjb.php','refill_xyz.php',
             'refill_zzx.php','refill_inner.php','refill_jiec.php','refill_yifa.php',
             'bridge_shr.php'

+ 3 - 0
helper/refill/RefillFactory.php

@@ -58,6 +58,9 @@ require_once(BASE_HELPER_PATH . '/refill/jiec/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/xc/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/xc/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/gftd/RefillOil.php');
+require_once(BASE_HELPER_PATH . '/refill/gftd/RefillCallBack.php');
+
 use Log;
 use mtopcard;
 use QueueClient;

+ 94 - 0
helper/refill/gftd/RefillCallBack.php

@@ -0,0 +1,94 @@
+<?php
+
+
+namespace refill\gftd;
+
+require_once(BASE_HELPER_PATH . '/refill/gftd/config.php');
+
+
+use refill;
+
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $input = $params;
+        unset($input['signature']);
+
+        $sign = $this->sign($input);
+        if ($params['signature'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $body = $this->body($params);
+        $body .= config::APP_SECRET;
+
+        return md5($body);
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($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}" . "=" . $v;
+                } else {
+                    $body .= "&" . "{$k}" . "=" . $v;
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+
+        $order_sn = $params['channelOrderNumber'];
+        $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'];
+        $data['official_sn'] = $params['voucher'];
+        $data['ch_trade_no'] = $params['orderNumber'];
+        Model('refill_order')->edit($order_id, $data);
+
+        //[$order_id, 成功失败, 是否能重试,接下来是否需要处理]
+        if ($status === 101) {
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 109) {
+            return [$order_id, false, true,true];
+        }
+        elseif ($status === 120) {
+            return [$order_id, false, false,false];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 141 - 0
helper/refill/gftd/RefillOil.php

@@ -0,0 +1,141 @@
+<?php
+
+
+namespace refill\gftd;
+
+require_once(BASE_HELPER_PATH . '/refill/gftd/config.php');
+
+
+use refill;
+use mtopcard;
+use Log;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(string $card_no,int $card_type,int $amount,array $other)
+    {
+        $params['appid'] = config::APP_ID;
+        $params['ts'] = time();
+
+        $params['productId'] = $this->product_id($amount,$card_type);
+        $params['outOrderNumber'] = $other['order_sn'];
+        $params['fuelCardNumber'] = $card_no;
+
+        $params['fuelCardUserName'] = "";
+        $params['fuelCardUserID'] = "";
+
+        $mobile = $this->make_mobile();
+        $params['telephone'] = $mobile;
+        $params['phoneNumber'] = $mobile;
+
+        return $params;
+    }
+
+    private function make_mobile()
+    {
+        $no = "1" . mt_rand(3000000000, 9999999999);
+        return $no;
+    }
+
+    private function product_id(int $amount,int $cart_type)
+    {
+        if($cart_type === mtopcard\PetroChinaCard)
+        {
+            switch ($amount) {
+                case 100: return 1;
+                case 200: return 2;
+                case 500: return 3;
+                case 1000: return 4;
+            }
+        }
+        else
+        {
+            switch ($amount) {
+                case 100: return 5;
+                case 200: return 6;
+                case 500: return 7;
+                case 1000: return 8;
+            }
+        }
+
+        return false;
+    }
+
+    private function sign($params)
+    {
+        $body = $this->body($params);
+        $body .= config::APP_SECRET;
+
+        return md5($body);
+    }
+
+    protected function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
+    private function body($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}" . "=" . $v;
+                } else {
+                    $body .= "&" . "{$k}" . "=" . $v;
+                }
+
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        $params = $this->req_params($card_no,$card_type,$amount,$input);
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $uri = config::ORDER_URL . "/fuelRecharge/create";
+        $resp = http_post_data($uri,json_encode($params), config::ExtHeaders);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+
+            if($resp['code'] == 0)
+            {
+                $data = $resp['data'];
+                return [true,$data['orderNumber']];
+            }
+            else {
+                return [false,$resp['message']];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        return [false,'未实现查询接口'];
+    }
+}

+ 24 - 0
helper/refill/gftd/RefillPhone.php

@@ -0,0 +1,24 @@
+<?php
+namespace refill\gftd;
+
+require_once(BASE_HELPER_PATH . '/refill/gftd/config.php');
+
+use refill;
+use refill\IRefillPhone;
+
+class RefillPhone extends IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    public function add($card_no,$card_type,$amount,$input)
+    {
+        return [false,'No Implement'];
+    }
+    public function query($refill_info)
+    {
+        return [false,'No Implement'];
+    }
+}

+ 18 - 0
helper/refill/gftd/config.php

@@ -0,0 +1,18 @@
+<?php
+
+
+namespace refill\gftd;
+
+
+class config
+{
+    const ORDER_URL = 'https://dev.oapi.chinasaltenergy.com/open-api'; #dev
+//    const ORDER_URL = 'https://oapi.chinasaltenergy.com/open-api';   #prod
+
+    const APP_ID= '24EE24A4D68EE181';
+    const APP_SECRET = 'B00D392356824C288E1A8A2C1415CC9C';
+
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/refill_gftd.php";
+//    const ExtHeaders = ['Content-Type: application/x-www-form-urlencoded' , 'Accept: application/json;charset=UTF-8'];
+    const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
+}

+ 3 - 2
helper/refill/yifa/RefillCallBack.php

@@ -49,11 +49,12 @@ class RefillCallBack implements refill\IRefillCallBack
         $data['ch_trade_no'] = $params['order_sn'];
         Model('refill_order')->edit($order_id, $data);
 
+        //[$order_id, 成功失败, 是否能重试,接下来是否需要处理]
         if ($status === 'success') {
-            return [$order_id, true, false,true,true];
+            return [$order_id, true, false,true];
         }
         elseif ($status === 'fail') {
-            return [$order_id, false, true,true,true];
+            return [$order_id, false, true,true];
         }
         else {
             return [$order_id, false, false,false];

+ 10 - 0
mobile/refill_gftd.php

@@ -0,0 +1,10 @@
+<?php
+
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
+
+$content = $_SERVER['post_content'];
+$input = json_decode($content,true);
+refill\RefillFactory::instance()->notify('gftd',$input);
+
+$ret = ['state' => "success"];
+echo (json_encode($ret));

+ 20 - 0
test/TestRefill.php

@@ -57,6 +57,12 @@ class TestRefill extends TestCase
             . sprintf('%06d', (float)microtime() * 1000000);
     }
 
+    public function testRandomMobile()
+    {
+        $no = "1" . mt_rand(1, 9999999999);
+        Log::record("phone no={$no}",Log::DEBUG);
+    }
+
     public function testBJBAddPhone()
     {
         $providers = new refill\bjb\RefillPhone([]);
@@ -130,6 +136,20 @@ class TestRefill extends TestCase
         $resp = $providers->add(1000111100021211884, 2, 100, ['order_sn' => '200229600556618886']);
     }
 
+    public function testGFTDOil()
+    {
+        $providers = new refill\gftd\RefillOil([]);
+        $resp = $providers->add(1000111100020445281, mtopcard\SinopecCard, 100, ['order_sn' => $this->make_sn()]);
+    }
+
+    public function testGFTDCB()
+    {
+        $data = '{"channelOrderNumber":"79091610959059372019","orderNumber":"GYFL1610959060397001","message":"充值成功","signature":"881036222bd8f067ff47d248c75f4c8d","voucher":"","status":101}';
+        $url = "http://192.168.1.220/mobile/refill_gftd.php?" . $data;
+        $resp = http_post_data($url, $data, ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;']);
+
+    }
+
     public function testJiecPhone()
     {
         $providers = new refill\jiec\RefillPhone([]);