Forráskód Böngészése

add xuyouoil channel to xyz

dong 1 éve
szülő
commit
ac17b45e05

BIN
helper/refill/api/xyz/xunyinoil/迅银开放平台采购接口-采购商.docx


+ 1 - 1
helper/refill/api/xyz/xuyou_sdm/config.php

@@ -11,7 +11,7 @@ class config
     const QUERY_URL = 'http://123.56.68.57:1008/hqorder/api/query';
     const BALANCE_URL = 'http://123.56.68.57:1008/hqorder/api/balance';
 
-    const MCHID = '1000000';
+    const MCHID = '1';
     const KEY = '52e4fd509410446a8259fd8a93de6c85';
 //    const NOTIFY_URL = BASE_SITE_URL . "/mobile/callback/refill_yongjia.php";
     const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";

+ 48 - 0
helper/refill/api/xyz/xuyouoil/RefillCallBack.php

@@ -0,0 +1,48 @@
+<?php
+namespace refill\xuyouoil;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xuyouoil/config.php');
+
+use refill;
+class RefillCallBack implements refill\IRefillCallBack
+{
+    public function verify($params): bool
+    {
+        $sign = $this->sign($params);
+        if ($params['sign'] == $sign) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function sign($params)
+    {
+        $mchid = config::MCHID;
+        $key = config::KEY;
+        $content  = "mchid={$mchid}&orderid={$params['orderid']}&oid={$params['oid']}&number={$params['number']}&status={$params['status']}&key={$key}";
+        return md5($content);
+    }
+
+    public function notify($params)
+    {
+        $order_sn = $params['orderid'];
+        $order_info = Model('vr_order')->getOrderInfoForNotify(['order_sn' => $order_sn]);
+        if (empty($order_info)) {
+            return [false, false, false, false, ''];
+        }
+
+        $order_id = $order_info['order_id'];
+        $status = intval($params['status']);
+        if ($status === 2) {
+            $official_sn = strtolower($params['voucher']) == 'null' ? '' : $params['voucher'];
+            $data['official_sn'] = $official_sn;
+            Model('refill_order')->edit($order_id, $data);
+            return [$order_id, true, false, true, $official_sn];
+        } elseif ($status === 3) {
+            return [$order_id, false, true, true, ''];
+        } else {
+            return [$order_id, false, false, false, ''];
+        }
+    }
+}

+ 169 - 0
helper/refill/api/xyz/xuyouoil/RefillOil.php

@@ -0,0 +1,169 @@
+<?php
+
+namespace refill\xuyouoil;
+
+require_once(BASE_HELPER_RAPI_PATH . '/xuyouoil/config.php');
+
+use refill;
+use Log;
+use mtopcard;
+
+class RefillOil extends refill\IRefillOil
+{
+    public function __construct($cfgs)
+    {
+        parent::__construct($cfgs);
+    }
+
+    private function req_params(int $phone, string $order_sn, $product_code, $province)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $order_sn;
+        $params['number'] = $phone;
+        $params['productid'] = $product_code;
+        $params['timestamp'] = $this->getMillisecond();
+        $params['backurl'] = config::NOTIFY_URL;
+        $params['youka'] = mtopcard\ProvinceList[$province];
+        return $params;
+    }
+
+
+    private function getProductCode($goods_id, $sys_pcode)
+    {
+        $thrid_refill = Model('thrid_refill');
+        $product = $thrid_refill->getProviderProduct($this->mStoreID,$goods_id,$sys_pcode);
+        if (empty($product)) {
+            return false;
+        } else {
+            return $product['channel_code'];
+        }
+    }
+
+    public function add($card_no, $card_type, $amount, $params, &$net_errno = 0)
+    {
+       # $goods_id = intval($params['goods_id']);
+       # $province = $params['province'] ?? -1;
+       # if($province < 0) {
+       #     return [false, '省份获取错误', false];
+       # }
+
+       # $product_code = $this->getProductCode($goods_id, $params['product_code']);
+       # if(empty($product_code)) {
+       #     return [false, '产品未开启', false];
+       # }
+       # Model('thrid_refill')->edit_third($params['order_id'], ['chcode' => $product_code]);
+
+        $params = $this->req_params($card_no, $params['order_sn'], $params['product_code'], $params['province']);
+        $sign = $this->sign($params);
+        $params['sign'] = $sign;
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::ORDER_URL, $params , config::ExtHeaders, $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['status'] === 0) {
+                return [true, $resp['oid'], false];
+            } elseif ($resp['status'] === -1) {
+                return [false, $resp['msg'], false];
+            } else {
+                $net_errno = "HTTP-998";
+                return [false, $resp['msg'], true];
+            }
+        }
+    }
+
+    public function query($refill_info)
+    {
+        $params['mchid'] = config::MCHID;
+        $params['orderid'] = $refill_info['order_sn'];
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&orderid={$params['orderid']}&key={$key}";
+        $params['sign'] = md5($content);
+
+        $params = json_encode($params);
+        $resp = http_post_data(config::QUERY_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误', ''];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误', ''];
+            }
+            else {
+                $offical_sn = '';
+                $status = $resp['status'];
+                if ($status === 2) {
+                    $offical_sn = $resp['voucher'];
+                    $updata['official_sn'] = $offical_sn;
+                    Model('refill_order')->edit($refill_info['order_id'], $updata);
+                    $order_state = ORDER_STATE_SUCCESS;
+                } elseif ($status === 3) {
+                    $order_state = ORDER_STATE_CANCEL;
+                } elseif ($status === 1) {
+                    $order_state = ORDER_STATE_SEND;
+                } elseif ($status === 4 && (time() - $refill_info['commit_time'] > 300)) {
+                    $order_state = ORDER_STATE_NOEXIST;
+                } else {
+                    return [false, $status, $offical_sn];
+                }
+                return [true, $order_state, $offical_sn];
+            }
+        }
+    }
+
+    public function balance()
+    {
+        $params['mchid'] = config::MCHID;
+        $key = config::KEY;
+        $content = "mchid={$params['mchid']}&key={$key}";
+        $params['sign'] = md5($content);
+        $params = json_encode($params);
+
+        $resp = http_post_data(config::BALANCE_URL, $params , config::ExtHeaders);
+
+        if (empty($resp)) {
+            return [false, '系统错误'];
+        }
+        else
+        {
+            Log::record($resp, Log::DEBUG);
+            $resp = json_decode($resp, true);
+            if (empty($resp)) {
+                return [false, '系统错误'];
+            } elseif ($resp['status'] === 1) {
+                return [true, $resp['balance']];
+            } else {
+                return [false, $resp['msg']];
+            }
+        }
+    }
+
+    private function sign($params)
+    {
+        $key = config::KEY;
+        $content  = "mchid={$params['mchid']}&orderid={$params['orderid']}&number={$params['number']}&productid={$params['productid']}";
+        $content .= "&timestamp={$params['timestamp']}&youka={$params['youka']}&key={$key}";
+        return md5($content);
+    }
+
+    /**
+     * 获取毫秒级别的时间戳
+     */
+    private function getMillisecond()
+    {
+        $cur = microtime (true);
+        return intval($cur * 1000);
+    }
+}

+ 18 - 0
helper/refill/api/xyz/xuyouoil/config.php

@@ -0,0 +1,18 @@
+<?php
+
+
+namespace refill\xuyouoil;
+
+class config
+{
+    #旭友油卡
+
+    const ORDER_URL = 'http://123.56.68.57:1008/hqorder/api/youkasubmit';
+    const QUERY_URL = 'http://123.56.68.57:1008/hqorder/api/query';
+    const BALANCE_URL = 'http://123.56.68.57:1008/hqorder/api/balance';
+
+    const MCHID = '1';
+    const KEY = '52e4fd509410446a8259fd8a93de6c85';
+    const NOTIFY_URL = "https://www.xyzshops.cn/mobile/signature.php";
+    const ExtHeaders = ['Content-Type: application/json'];
+}

BIN
sdm_business_code.xlsx


+ 76 - 0
test/TestExcelToDb.php

@@ -0,0 +1,76 @@
+<?php
+use PHPUnit\Framework\TestCase;
+use const mtopcard\ProvinceList;
+const APP_ID = 'test';
+define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
+
+require_once(BASE_ROOT_PATH . '/global.php');
+require_once(BASE_ROOT_PATH . '/fooder.php');
+require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel.php");
+require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel/Reader/Excel2007.php");
+
+const LocalTest = 1;
+const NetTest = 2;
+
+const CurrentTest = NetTest;
+
+class TestExcelToDb extends TestCase
+{
+    public function testImportingDataToDb()
+    {
+        $objReader = new PHPExcel_Reader_Excel2007;
+        $objPHPExcel = $objReader->load("../sdm_business_code.xlsx");
+        $sheetCount = $objPHPExcel->getSheetCount();
+
+        $exportData = function ($sheetCount) use($objPHPExcel)
+        {
+            $businessCode = [];
+            for ($i=0; $i<$sheetCount; $i++){
+                $sheet = $objPHPExcel->getSheet($i);
+                $businessCode[$i]["sheet_name"] = $sheet->getTitle();
+                foreach($sheet->getRowIterator() as $key => $row) {
+                    $cellIterator = $row->getCellIterator();
+                    $cellIterator->setIterateOnlyExistingCells(true);
+                    foreach ($cellIterator as $cell) {
+                        if ($key > 1) {
+                            $columnValue = (string)$cell->getValue();
+                            $businessCode[$i]["data"][$key-2][] = $columnValue;
+                        }
+                    }
+                }
+            }
+            return $businessCode;
+        };
+
+       $data = $exportData($sheetCount);
+    }
+
+
+    public function testTimes()
+    {
+        $timed = date("ymdhm", time());
+
+    }
+
+
+    public function testMd5()
+    {
+        $m = md5("123", true);
+    }
+
+
+    public function testGuid()
+    {
+//        if (function_exists('com_create_guid') === true) {
+//           $guid =  strtolower(str_replace('-', '', trim(com_create_guid(), '{}')));
+//        }
+//
+//        $guid = sprintf('%04x%04x%04x%04x%04x%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
+        $str = md5(uniqid(mt_rand(), true));
+        $uuid  = substr($str,0,8);
+        $uuid .= substr($str,8,4);
+        $uuid .= substr($str,12,4);
+        $uuid .= substr($str,16,4);
+        $uuid .= substr($str,20,12);
+    }
+}

+ 20 - 6
test/TestRefill.php

@@ -220,7 +220,7 @@ class TestRefill extends TestCase
 
     public function testAmPhone()
     {
-//        $provider = new refill\aming\RefillPhone([]);
+//        $provider = new refill\aming\RefillOil([]);
 //        $resp = $provider->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
         $input['result'] = 'fail';
         $input['msg'] = 0;
@@ -248,7 +248,7 @@ class TestRefill extends TestCase
 
     public function testRuishunPhone()
     {
-//        $provider = new refill\ruishun\RefillPhone([]);
+//        $provider = new refill\ruishun\RefillOil([]);
 //        $resp = $provider->add(18500608333, 5, 10, ['order_sn' => $this->make_sn()]);
         $input['result'] = 'fail';
         $input['msg'] = 0;
@@ -3622,7 +3622,7 @@ class TestRefill extends TestCase
 
     public function testAmingjd()
     {
-//        $provider = new refill\amingjd\RefillPhone([]);
+//        $provider = new refill\amingjd\RefillOil([]);
 //        $resp = $provider->add(13699279618, 5, 30, ['order_sn' => $this->make_sn()]);
 //        $resp = $provider->query(['order_sn' => '42301616475989518588']);
         $body = '{"order_id":"83321616478215494884","mchid":"10003","tel":"13699279618","price":"30.00","sign":"01c49620c155a80bc43cecc2b1651868","status":"0","out_order_id":"0"}';
@@ -3962,7 +3962,7 @@ class TestRefill extends TestCase
 
     public function testFenshengPhone()
     {
-        $file = BASE_HELPER_RAPI_PATH . "/qianqian/RefillPhone.php";
+        $file = BASE_HELPER_RAPI_PATH . "/qianqian/RefillOil.php";
         if(!file_exists($file)){
             Log::record("provider api file={$file} not exist.",Log::DEBUG);
             return false;
@@ -5109,7 +5109,7 @@ class TestRefill extends TestCase
         $x = \refill\util::async_add(['xxxx' => 1],4);
     }
 
-    private function getProvider($name,$type = 'RefillPhone')
+    private function getProvider($name,$type = 'RefillOil')
     {
         $file = BASE_HELPER_RAPI_PATH . "/$name/{$type}.php";
         if(!file_exists($file)){
@@ -5267,7 +5267,7 @@ class TestRefill extends TestCase
     public function testXuyoufs_Add()
     {
         $provider = $this->getProvider("xuyou_sdm");
-        $resp = $provider->add(18074608795, 6, 100, ['order_sn' => $this->make_sn(), 'province' => "肥西供电公司", 'product_code' => 9990001]);;
+        $resp = $provider->add(18074608795, 6, 100, ['order_sn' => $this->make_sn(), 'province' => "肥西供电公司", 'product_code' => 9990001]);
     }
 
     public function testXuyoufs_Balance()
@@ -5453,6 +5453,20 @@ class TestRefill extends TestCase
         $provider = $this->getProvider('kaisinuojy', 'RefillOil');
         $resp = $provider->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
     }
+
+
+    public function testxuyouoil_Balance()
+    {
+        $provider = $this->getProvider('xuyouoil', 'RefillOil');
+        [$succ, $val] = $provider->balance();
+    }
+
+    public function testxuyouoil_Add()
+    {
+        $provider = $this->getProvider("xuyouoil", "RefillOil");
+        $resp = $provider->add(18074608795, 6, 100, ['order_sn' => $this->make_sn(), 'province' => 1, 'product_code' => 990001]);
+    }
+
 }
 
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefill::testLoadBlack)( .*)?$/" --test-suffix TestRefill.php /var/www/html/test