Selaa lähdekoodia

update factory require bdt refill test add bdtoil

ayHaru 4 vuotta sitten
vanhempi
commit
f93633ec93
2 muutettua tiedostoa jossa 75 lisäystä ja 74 poistoa
  1. 3 0
      helper/refill/RefillFactory.php
  2. 72 74
      test/TestRefill.php

+ 3 - 0
helper/refill/RefillFactory.php

@@ -30,6 +30,9 @@ require_once(BASE_HELPER_PATH . '/refill/bxtwt/RefillCallBack.php');
 require_once(BASE_HELPER_PATH . '/refill/bjb/RefillPhone.php');
 require_once(BASE_HELPER_PATH . '/refill/bjb/RefillCallBack.php');
 
+require_once(BASE_HELPER_PATH . '/refill/bdt/RefillPhone.php');
+require_once(BASE_HELPER_PATH . '/refill/bdt/RefillCallBack.php');
+
 use Log;
 use mtopcard;
 use QueueClient;

+ 72 - 74
test/TestRefill.php

@@ -22,19 +22,18 @@ const CurrentTest = NetTest;
 class TestRefill extends TestCase
 {
     private $mReqHost = '';
-    private $mKey='';
+    private $mKey = '';
     private $mMchid = 0;
 
     public function __construct(?string $name = null, array $data = [], $dataName = '')
     {
         parent::__construct($name, $data, $dataName);
 
-        if(CurrentTest == LocalTest) {
+        if (CurrentTest == LocalTest) {
             $this->mReqHost = BASE_SITE_URL;
             $this->mMchid = 1;
             $this->mKey = '1ff02223b771c0414468c8892151c602';
-        }
-        else {
+        } else {
             $this->mReqHost = 'https://www.xyzshops.cn';
             $this->mMchid = 1092;
             $this->mKey = '210fe406954220f56085997d6a4c5b80';
@@ -50,22 +49,23 @@ class TestRefill extends TestCase
     {
         $providers = refill\RefillFactory::instance();
     }
+
     private function make_sn()
     {
-        return mt_rand(1000,9999)
-            . sprintf('%010d',time())
-            . sprintf('%06d', (float) microtime() * 1000000);
+        return mt_rand(1000, 9999)
+            . sprintf('%010d', time())
+            . sprintf('%06d', (float)microtime() * 1000000);
     }
 
     public function testBJBAddPhone()
     {
         $providers = new refill\bjb\RefillPhone([]);
         for ($i = 3; $i > 0; --$i) {
-            $resp = $providers->add(13911129867,4,10,['order_sn' => $this->make_sn()]);
-            $resp = $providers->add(18500608333,4,10,['order_sn' => $this->make_sn()]);
-            $resp = $providers->add(18510683168,4,10,['order_sn' => $this->make_sn()]);
-            $resp = $providers->add(18513846008,4,10,['order_sn' => $this->make_sn()]);
-            $resp = $providers->add(18518237398,4,10,['order_sn' => $this->make_sn()]);
+            $resp = $providers->add(13911129867, 4, 10, ['order_sn' => $this->make_sn()]);
+            $resp = $providers->add(18500608333, 4, 10, ['order_sn' => $this->make_sn()]);
+            $resp = $providers->add(18510683168, 4, 10, ['order_sn' => $this->make_sn()]);
+            $resp = $providers->add(18513846008, 4, 10, ['order_sn' => $this->make_sn()]);
+            $resp = $providers->add(18518237398, 4, 10, ['order_sn' => $this->make_sn()]);
         }
     }
 
@@ -73,10 +73,10 @@ class TestRefill extends TestCase
     {
         $x = serialize(['47.99.57.105']);
         $ips = unserialize('a:1:{i:0;s:12:"47.99.57.105";}');
-        if(!empty($ips)) {
+        if (!empty($ips)) {
             $addr = '47.99.57.105';
-            Log::record("request ip:{$addr}",Log::DEBUG);
-            if(!in_array($addr,$ips)) {
+            Log::record("request ip:{$addr}", Log::DEBUG);
+            if (!in_array($addr, $ips)) {
                 throw new Exception("请求地址不在白名单中");
             }
         }
@@ -86,7 +86,7 @@ class TestRefill extends TestCase
     {
         global $config;
         $providers = new \refill\bjb\RefillPhone($config['phone_providers']['bjb']);
-        $resp = $providers->add(18500608333,5,50,['order_sn' => '200229600551218886']);
+        $resp = $providers->add(18500608333, 5, 50, ['order_sn' => '200229600551218886']);
 
         //{"ack":"success","message":{"order_number":13281474,"charged_amount":"48.750","shipping_status":"5","shipping_status_desc":"未发货"}}
         //$_POST='{"order_number":13281474,"shipping_status":1,"shipping_status_desc":"已发货","shipping_status_message":"","sign":"05863f9931ed69a70e456222f057dfdd","voucher":"110103307162012081746340295254","vouchertype":"","voucherurl":"","tradeNo":"200649600557718888"}';
@@ -102,6 +102,12 @@ class TestRefill extends TestCase
 //        $ret = refill\RefillFactory::instance()->notify('beixt',$params);
     }
 
+    public function testBdtOil()
+    {
+        $providers = new \refill\bdt\RefillOil([]);
+        $resp = $providers->add(1000111100021211884,2,100,['order_sn' => '200229600556618886']);
+    }
+
     public function testBxtwtCB()
     {
         $data = '{"order_number":18219726,"shipping_status":4,"shipping_status_desc":"发货失败","shipping_status_message":"","sign":"863b4d972f2a4d39a9af7396879116c4","voucher":"","vouchertype":"","voucherurl":"","tradeNo":"100662475851197741"}';
@@ -129,13 +135,13 @@ class TestRefill extends TestCase
         $url = "https://www.xyzshops.cn/mobile/refill_bxtwt.php";
 
         $headers = ['Content-Type: application/json'];
-        $resp = http_post_data($url,$data,$headers);
+        $resp = http_post_data($url, $data, $headers);
     }
 
     public function testInput()
     {
         $input = fopen("php://input", "rw");
-        file_put_contents($input,'xxxx');
+        file_put_contents($input, 'xxxx');
         $content = file_get_contents('php://input');
     }
 
@@ -145,23 +151,20 @@ class TestRefill extends TestCase
         $data = 'onlystr=190661874318128632&sign=9eb60765c356341fd41c9bec6526f46a&amt=1000&notifyurl=https%3A%2F%2Fwww.xyzshops.cn%2Fmobile%2Frefill_suhc.php&jdno&cardtype=Sinoepc&batchid=25940&cardno=1000111100012304048&orgid=1590993600&status=2';
 
         $params = preg_split('/&/', $data);
-        foreach ($params as $pair)
-        {
+        foreach ($params as $pair) {
             $kv = explode('=', $pair);
             $count = count($kv);
-            if($count === 1) {
+            if ($count === 1) {
                 $key = $kv[0];
                 $val = "";
-            }
-            elseif($count === 2) {
+            } elseif ($count === 2) {
                 $key = $kv[0];
                 $val = $kv[1];
-            }
-            else {
+            } else {
                 continue;
             }
 
-            Log::record("{$key}:{$val}",Log::DEBUG);
+            Log::record("{$key}:{$val}", Log::DEBUG);
         }
     }
 
@@ -172,13 +175,13 @@ class TestRefill extends TestCase
         $params = ['mchid' => 1092,
             'cardno' => '1000111100020445281',
             'amount' => "100",
-            "act"=>"refill",
-            "op"=>"add",
+            "act" => "refill",
+            "op" => "add",
             'order_sn' => $this->make_sn(),
-            'notifyurl'=> $notifyurl];
+            'notifyurl' => $notifyurl];
 
-        $resp = $this->send_md5($url,$params);
-        Log::record($resp,Log::DEBUG);
+        $resp = $this->send_md5($url, $params);
+        Log::record($resp, Log::DEBUG);
     }
 
     public function testAddPhoe()
@@ -190,20 +193,19 @@ class TestRefill extends TestCase
             18518237398];
         $amount = 10;
 
-        for ($i = 0; $i < 3; $i++)
-        {
+        for ($i = 0; $i < 3; $i++) {
             foreach ($phones as $phone) {
                 $url = $this->mReqHost . "/mobile/index.php";
                 $params = ['mchid' => 1092,
                     'cardno' => $phone,
                     'amount' => $amount,
-                    "act"=>"refill",
-                    "op"=>"add",
+                    "act" => "refill",
+                    "op" => "add",
                     'order_sn' => $this->make_sn(),
-                    'notifyurl'=> $this->mReqHost . "/mobile/refill_xyz.php"];
+                    'notifyurl' => $this->mReqHost . "/mobile/refill_xyz.php"];
 
-                $resp = $this->send_md5($url,$params);
-                Log::record($resp,Log::DEBUG);
+                $resp = $this->send_md5($url, $params);
+                Log::record($resp, Log::DEBUG);
             }
         }
     }
@@ -212,10 +214,10 @@ class TestRefill extends TestCase
     {
         $req_url = $this->mReqHost . '/mobile/index.php';
         $params = ['mchid' => $this->mMchid,
-            "act"=>"refill",
-            "op"=>"goods"];
+            "act" => "refill",
+            "op" => "goods"];
 
-        $resp = $this->send_md5($req_url,$params);
+        $resp = $this->send_md5($req_url, $params);
     }
 
     public function testQueryFactory()
@@ -232,17 +234,17 @@ class TestRefill extends TestCase
         $notifyurl = 'https://www.xyzshops.cn/mobile/signature.php';
 
         $params = ['mchid' => 1,
-            "act"=>"refill",
-            "op"=>"query",
+            "act" => "refill",
+            "op" => "query",
             'order_sn' => "13281476"];
 
-        $resp = $this->send_md5($req_url,$params);
+        $resp = $this->send_md5($req_url, $params);
     }
 
     public function testRemoveSession()
     {
-        $resp = http_request(BASE_SITE_URL . "/mobile/signature.php",[],'POST');    }
-
+        $resp = http_request(BASE_SITE_URL . "/mobile/signature.php", [], 'POST');
+    }
 
 
     public function testSuhcCB()
@@ -253,7 +255,7 @@ class TestRefill extends TestCase
 
         $params = ['onlystr' => '920660917672249741',
             'amt' => 100,
-            'jdno'=>'',
+            'jdno' => '',
             'notifyurl' => $notifyurl,
             'cardtype' => 'Sinoepc',
             'batchid' => 18512,
@@ -264,8 +266,8 @@ class TestRefill extends TestCase
         $sign = $this->md5_sign($params);
         $params['sign'] = $sign;
 
-        $resp = http_request($notifyurl,$params,'POST');
-        Log::record($resp,Log::DEBUG);
+        $resp = http_request($notifyurl, $params, 'POST');
+        Log::record($resp, Log::DEBUG);
     }
 
     public function testZFKJ()
@@ -278,12 +280,12 @@ class TestRefill extends TestCase
         $params = ['mchid' => 1090,
             'cardno' => '100112121212212133',
             'amount' => '10',
-            "act"=>"refill",
-            "op"=>"add",
+            "act" => "refill",
+            "op" => "add",
             'order_sn' => 'PH2012261356569433',
-            'notifyurl'=> 'https://qzcz.edusahoo.com.cn/index/index/callback'];
+            'notifyurl' => 'https://qzcz.edusahoo.com.cn/index/index/callback'];
 
-        $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php',$params);
+        $resp = $this->send_md5(BASE_SITE_URL . '/mobile/index.php', $params);
     }
 
     protected function check_empty($value)
@@ -304,10 +306,8 @@ class TestRefill extends TestCase
 
         $body = "";
         $i = 0;
-        foreach ($params as $k => $v)
-        {
-            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1))
-            {
+        foreach ($params as $k => $v) {
+            if (false === $this->check_empty($v) && "@" != substr($v, 0, 1)) {
                 if ($i == 0) {
                     $body .= "{$k}" . "=" . urldecode($v);
                 } else {
@@ -328,7 +328,7 @@ class TestRefill extends TestCase
         $logic->NotifyMerchantComplete(['order_id' => 289]);
     }
 
-    private function send($url,$params)
+    private function send($url, $params)
     {
         $mchid = $params['mchid'];
         $pri_key = BASE_DATA_PATH . "/api/merchant/key/{$mchid}_pri.pem";
@@ -342,19 +342,19 @@ class TestRefill extends TestCase
         $sign = base64_encode($signed);
         $params['sign'] = $sign;
 
-        $resp = http_request($url,$params,'POST');
-        Log::record("resp:{$resp}",Log::DEBUG);
+        $resp = http_request($url, $params, 'POST');
+        Log::record("resp:{$resp}", Log::DEBUG);
     }
 
-    private function send_md5($url,$params)
+    private function send_md5($url, $params)
     {
         $body = $this->body($params);
         $body .= "&key={$this->mKey}";
 //        $body .= "&key=ZhongFKJZhongFKJZhongFKJ";
         $params['sign'] = md5($body);
 
-        $resp = http_request($url,$params,'POST');
-        Log::record("resp:{$resp}",Log::DEBUG);
+        $resp = http_request($url, $params, 'POST');
+        Log::record("resp:{$resp}", Log::DEBUG);
 
         return $resp;
     }
@@ -362,7 +362,7 @@ class TestRefill extends TestCase
     public function testCardType()
     {
         $cardno = '1000111100021211884';
-        $ret = preg_match( '/^1[0-9]{18}$/',$cardno,$matches);
+        $ret = preg_match('/^1[0-9]{18}$/', $cardno, $matches);
     }
 
     public function testMtrand()
@@ -377,14 +377,14 @@ class TestRefill extends TestCase
         $key = file_get_contents($pri_key);
         $pri = openssl_get_privatekey($key);
 
-        $params = ['MCHID' => $mchid,'cardno' => '1000111100021211884','amt' => "100","act"=>"refill","op"=>"addoil"];
+        $params = ['MCHID' => $mchid, 'cardno' => '1000111100021211884', 'amt' => "100", "act" => "refill", "op" => "addoil"];
         $body = $this->body($params);
 
         openssl_sign($body, $signed, $pri);
         $sign = base64_encode($signed);
         $params['sign'] = $sign;
 
-        $resp = http_request(BASE_SITE_URL . "/mobile/index.php",$params,'POST');
+        $resp = http_request(BASE_SITE_URL . "/mobile/index.php", $params, 'POST');
     }
 
     private function body($params)
@@ -392,10 +392,8 @@ class TestRefill extends TestCase
         ksort($params);
         $body = "";
         $i = 0;
-        foreach ($params as $k => $v)
-        {
-            if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1))
-            {
+        foreach ($params as $k => $v) {
+            if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
                 if ($i == 0) {
                     $body .= "{$k}" . "=" . urlencode($v);
                 } else {
@@ -421,17 +419,17 @@ class TestRefill extends TestCase
 
     public function testKsort()
     {
-        $age= ["Peter"=>"35","Ben"=>"37","Joe"=>"43"];
+        $age = ["Peter" => "35", "Ben" => "37", "Joe" => "43"];
         ksort($age);
 
-        foreach($age as $x=>$x_value)
-        {
+        foreach ($age as $x => $x_value) {
             echo "Key=" . $x . ", Value=" . $x_value;
             echo "<br>";
         }
     }
 
-    public function testip(){
+    public function testip()
+    {
         $model_merchant = Model('merchant');
         $merchant_info = $model_merchant->getMerchantInfo(['mchid' => 1]);
         $ipwhitelist = unserialize($merchant_info['ip_white_list']);