Parcourir la source

add feinimoshu api to xyz

stanley-king il y a 3 ans
Parent
commit
2483e44e21

+ 13 - 1
data/config/xyz/refill.ini.php

@@ -133,6 +133,17 @@ $lingzh_oil = ['name' => 'lingzhoil', 'store_id' => 56, 'qualitys' => '1',
     ],
     'period' => [], 'refill_type' => 'api'];
 
+$feinimoshu_oil = ['name' => 'feinimoshu', 'store_id' => 57, 'qualitys' => '1',
+    'amount' => [
+        50 => [['goods_id' => 6589, 'price' => 48.5, 'quality' => 1, 'card_type' => 'sinopec,petrochina']],
+        100 => [['goods_id' => 6590, 'price' => 97, 'quality' => 1, 'card_type' => 'sinopec,petrochina']],
+        200 => [['goods_id' => 6591, 'price' => 194, 'quality' => 1, 'card_type' => 'sinopec,petrochina']],
+        500 => [['goods_id' => 6592, 'price' => 485, 'quality' => 1, 'card_type' => 'sinopec,petrochina']],
+        1000 => [['goods_id' => 6593, 'price' => 970, 'quality' => 1, 'card_type' => 'sinopec,petrochina']],
+        2000 => [['goods_id' => 6594, 'price' => 1940, 'quality' => 1, 'card_type' => 'sinopec,petrochina']]
+    ],
+    'period' => [], 'refill_type' => 'api'];
+
 $oil_providers = [
     ['name' => 'tianjt', 'cfg' => $tianjt_oil],
     ['name' => 'suhctm', 'cfg' => $suhctm_oil],
@@ -145,7 +156,8 @@ $oil_providers = [
     ['name' => 'yichangt', 'cfg' => $yichangt_oil],
     ['name' => 'jumi', 'cfg' => $jumi_oil],
     ['name' => 'zeheng', 'cfg' => $zeheng_oil],
-    ['name' => 'lingzhoil', 'cfg' => $lingzh_oil]
+    ['name' => 'lingzhoil', 'cfg' => $lingzh_oil],
+    ['name' => 'feinimoshu', 'cfg' => $feinimoshu_oil]
 ];
 $config['oil_providers'] = $oil_providers;
 

+ 68 - 0
helper/refill/api/xyz/feinimoshu/RefillCallBack.php

@@ -0,0 +1,68 @@
+<?php
+
+
+namespace refill\feinimoshu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/feinimoshu/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['appid'] == config::APPID && $params['signature'] == $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($input)
+    {
+        $key = config::APPKEY;
+        $body = config::body($input);
+        $body .= "&token={$key}";
+
+        return strtolower(md5($body));
+    }
+
+    //[$order_id, $success, $can_try, $need_handle]
+    public function notify($params)
+    {
+        $status = intval($params['status']);
+        $order_sn = $params['merchant_order_id'];
+        $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 === 2) {
+            $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false,true];
+        }
+        elseif ($status === 3) {
+            return [$order_id, false, true,true];
+        }
+        else {
+            return [$order_id, false, false,false];
+        }
+    }
+}

+ 126 - 0
helper/refill/api/xyz/feinimoshu/RefillOil.php

@@ -0,0 +1,126 @@
+<?php
+namespace refill\feinimoshu;
+
+require_once(BASE_HELPER_RAPI_PATH . '/feinimoshu/config.php');
+
+use refill;
+use Log;
+
+class RefillOil extends refill\IRefillPhone
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $card_no, int $card_type, int $amount, string $order_sn)
+    {
+        $params['appid'] = config::APPID;
+        $params['notify'] = config::NOTIFY_URL;
+        $params['card'] = $card_no;
+        $params['order'] = $order_sn;
+
+        $producd = config::getProduct($card_type, $amount);
+        if ($producd == false) {
+            Log::record("找不到合适的产品",Log::ERR);
+            return false;
+        } else {
+            $params['proid'] = $producd;
+            return $params;
+        }
+    }
+
+
+    public function add($card_no, $card_type,$amount,$input)
+    {
+        $order_sn = $input['order_sn'];
+        $params = $this->req_params($card_no,$card_type,$amount,$order_sn);
+        if(empty($params)) {
+            return [false,"上游{$this->name()}产品不支持:{$card_type}-{$amount}",true];
+        }
+
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::ORDER_URL,$params,'GET');
+        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'] == 1) {
+                return [true, $resp['data']['order'], false];
+            } else {
+                return [false, $resp['info'], false];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['appid'] = config::APPID;
+        $params['morder'] = $refill_info['order_sn'];
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::QUERY_URL,$params);
+        if (empty($resp)) {
+            return [false,'系统错误'];
+        }
+        else
+        {
+
+            Log::record($resp,Log::DEBUG);
+            $resp = json_decode($resp,true);
+
+            if (empty($resp)) {
+                return [false, '返回值错误'];
+            }
+
+            $code = intval($resp['code']);
+            $status = intval($resp['data']['status']);
+
+            if ($code != 1) {
+                return [false, $resp['info']];
+            } elseif ($status == 2) {
+                $order_state = ORDER_STATE_SUCCESS;
+                $data['official_sn'] = strtolower($params['vnum']) == 'null' ? '' : $params['vnum'];
+                Model('refill_order')->edit($refill_info['order_id'], $data);
+            } elseif ($status == 3) {
+                $order_state = ORDER_STATE_CANCEL;
+            } else {
+                $order_state = ORDER_STATE_SEND;
+            }
+
+            return [true, $order_state];
+        }
+    }
+
+    public function balance()
+    {
+        $params['appid'] = config::APPID;
+        $sign = $this->sign($params);
+        $params['signature'] = $sign;
+
+        $resp = http_request(config::QUERY_URL,$params);
+        if($resp === false) {
+            return [false,'系统错误'];
+        }
+        else {
+
+        }
+    }
+
+    private function sign($input)
+    {
+        $key = config::APPKEY;
+        $body = config::body($input);
+        $body .= "&token={$key}";
+
+        return strtolower(md5($body));
+    }
+}

+ 79 - 0
helper/refill/api/xyz/feinimoshu/config.php

@@ -0,0 +1,79 @@
+<?php
+
+
+namespace refill\feinimoshu;
+
+use mtopcard;
+class config
+{
+    const CHANNEL_HOST = 'http://122.114.168.35';
+    const ORDER_URL = config::CHANNEL_HOST . '/gateway/api.run/submit';
+    const QUERY_URL = config::CHANNEL_HOST . '/gateway/api.run/order';
+    const BALANCE_URL = config::CHANNEL_HOST . '/gateway/api.run/account';
+
+    const APPID = 'CZ30533982';
+    const APPKEY = 'lvrg4xoqvrozuq2irjza2a6dlenrsv';
+    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_feinimoshu.php";
+
+    static function getProduct($card_type,$amount)
+    {
+        if ($card_type == mtopcard\PetroChinaCard)
+        {
+            switch ($amount) {
+                case 50: return 10006;
+                case 100: return 10007;
+                case 200: return 10008;
+                case 500: return 10009;
+                case 1000: return 10010;
+                case 2000: return 10011;
+                default: return false;
+            }
+        }
+        elseif ($card_type == mtopcard\SinopecCard) {
+            switch ($amount) {
+                case 50: return 10000;
+                case 100: return 10001;
+                case 200: return 10002;
+                case 500: return 10003;
+                case 1000: return 10004;
+                case 2000: return 10005;
+                default: return false;
+            }
+        }
+        else {
+            return false;
+        }
+    }
+
+    public static function body($params)
+    {
+        ksort($params);
+        $body = "";
+        $i = 0;
+        foreach ($params as $k => $v)
+        {
+            if (false === self::check_empty($v) && "@" != substr($v, 0, 1))
+            {
+                if ($i == 0) {
+                    $body .= "{$k}" . "=" . urlencode($v);
+                } else {
+                    $body .= "&" . "{$k}" . "=" . urlencode($v);
+                }
+                $i++;
+            }
+        }
+        return $body;
+    }
+
+    private static function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+}

+ 4 - 0
mobile/callback/refill_feinimoshu.php

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

+ 13 - 12
test/TestRefillThird.php

@@ -2,8 +2,6 @@
 
 
 use PHPUnit\Framework\TestCase;
-use refill\lingzhdl\config;
-use function aop\stripPKSC7Padding;
 
 define('APP_ID', 'test');
 define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
@@ -13,6 +11,8 @@ require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_HELPER_PATH . '/refill_proxy.php');
+require_once(BASE_CORE_PATH . '/framework/function/http.php');
+
 
 
 class TestRefillThird extends TestCase
@@ -166,18 +166,19 @@ class TestRefillThird extends TestCase
             ['order_sn' => $this->make_sn(),
                 'goods_id' => 6559,
                 'quantity'=>5,'product_code'=>'XYZ100744','third_card_type'=>1]);
-//        $resp = $providers->query(['order_sn' => '59911615124025101286']);
-//        $input['usr'] = 1;
-//        $input['ord'] = '52741615119546453690';
-//        $input['bz'] = '';
-//        $input['state'] = 2;
-//        $input['sgn'] = 'FFCBB75C307154DD306F4EC75BB69A6D';
-//        refill\RefillFactory::instance()->notify('lingzhthird',$input);
     }
 
-    private function getProvider($name)
+    public function testFNMS()
+    {
+        $providers = $this->getProvider('feinimoshu','RefillOil');
+        $order_sn = $this->make_sn();
+        [$state, $ch_order, $neterr] = $providers->add(1000111100021211884, 2, 50, ['order_sn' => $order_sn]);
+        $providers->query(['ch_trade_no' => $ch_order,'order_sn' => $order_sn]);
+    }
+
+    private function getProvider($name,$type = 'RefillPhone')
     {
-        $file = BASE_HELPER_RAPI_PATH . "/$name/RefillPhone.php";
+        $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
         if(!file_exists($file)){
             Log::record("provider api file={$file} not exist.",Log::DEBUG);
             return false;
@@ -186,7 +187,7 @@ class TestRefillThird extends TestCase
             Log::record("file={$file} load success.",Log::DEBUG);
         }
 
-        $class_name = "refill\\{$name}\\RefillPhone";
+        $class_name = "refill\\{$name}\\{$type}";
         if (class_exists($class_name, false)) {
             $caller = new $class_name([]);
             return $caller;