Prechádzať zdrojové kódy

guochuang and guochuang_nation update

xiaoyu 3 rokov pred
rodič
commit
eb15abb29f

+ 30 - 28
helper/refill/api/xyz/guochuang/RefillPhone.php

@@ -28,7 +28,7 @@ class RefillPhone extends refill\IRefillPhone
         }
     }
 
-    private function req_params(int $phone, int $amount, int $card_type, string $order_sn)
+    private function add_params(int $phone, int $amount, int $card_type, string $order_sn,$regin_no)
     {
         $params['phone'] = $phone;
         $params['phoneType'] = config::operator[$card_type];
@@ -36,12 +36,17 @@ class RefillPhone extends refill\IRefillPhone
         $params['outerId'] = $order_sn;
         $params['callBackUrl'] = config::NOTIFY_URL;
         $params['speed'] = 0;
+        $params['provId'] = config::ProvinceMap[$regin_no];
 
-        return $params;
+        if(empty($params['provId'])) {
+            return false;
+        }
+        else {
+            return $params;
+        }
     }
 
-    //统一请求
-    private function url_request($params,$service)
+    private function form_uri($params, $service)
     {
         $get_params['service'] = $service;
         $get_params['userId'] = config::UserId;
@@ -51,34 +56,27 @@ class RefillPhone extends refill\IRefillPhone
         $get_params['sign'] = $sign;
 
         $url = config::API_URL;
-        $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($get_params) ? http_build_query($get_params) : $get_params);
-        return http_request($url, $params, 'POST', false, []);
+        $uri = $url . (strpos($url, '?') ? '&' : '?') . (is_array($get_params) ? http_build_query($get_params) : $get_params);
+
+        return $uri;
     }
 
-    public function add($card_no, $card_type, $amount, $params,&$net_errno = 0)
+    public function add($card_no, $card_type, $amount, $input, &$net_errno = 0)
     {
-        $order_sn = $params['order_sn'];
-        $regin_no = $params['regin_no'] ?? -1;
+        $order_sn = $input['order_sn'];
+        $regin_no = $input['regin_no'] ?? -1;
         if($regin_no <= 0) {
             return [false, '省份获取错误', false];
         }
 
-        $params = $this->req_params($card_no, $amount, $card_type, $order_sn);
-        $params['provId'] = config::ProvinceMap[$regin_no];
-        if(empty($params['provId'])) {
-            return [false, '省份获取错误', false];
+        $params = $this->add_params($card_no, $amount, $card_type, $order_sn,$regin_no);
+        if($params === false) {
+            return [false, '省份信息错误', false];
         }
 
-        $get_params['service'] = 'order.phone.charge';
-        $get_params['userId'] = config::UserId;
-        $get_params['ts'] = $this->getMillisecond();
-
-        $sign = $this->sign($params,$get_params);
-        $get_params['sign'] = $sign;
-        $url = config::API_URL;
-        $url = $url . (strpos($url, '?') ? '&' : '?') . (is_array($get_params) ? http_build_query($get_params) : $get_params);
+        $uri = $this->form_uri($params,'order.phone.charge');
+        $resp = http_request($uri, $params, 'POST', false, [], $net_errno);
 
-        $resp = http_request($url, $params, 'POST', false, [], $net_errno);
         if (empty($resp)) {
             return [false, '系统错误', true];
         }
@@ -90,7 +88,7 @@ class RefillPhone extends refill\IRefillPhone
             $code = $resp['code'];
             if (empty($resp)) {
                 return [false, '系统错误', true];
-            } elseif ($code == 'SUCCESS') {
+            } elseif ($code === 'SUCCESS') {
                 return [true, $resp['id'], false];
             } elseif (in_array($code, config::ORDER_ERR_CODE)) {
                 return [false, $code, false];
@@ -111,7 +109,8 @@ class RefillPhone extends refill\IRefillPhone
         $params['id'] = '';
         $params['outerId'] = $refill_info['order_sn'];
 
-        $resp = $this->url_request($params,'order.status.query');
+        $uri = $this->form_uri($params,'order.status.query');
+        $resp = http_request($uri, $params, 'POST');
 
         if (empty($resp)) {
             return [false, '系统错误'];
@@ -125,7 +124,7 @@ class RefillPhone extends refill\IRefillPhone
             {
                 return [false, '系统错误'];
             }
-            elseif ($code == 'SUCCESS')
+            elseif ($code === 'SUCCESS')
             {
                 $status = $resp['status'];
 
@@ -154,7 +153,8 @@ class RefillPhone extends refill\IRefillPhone
 
     public function balance()
     {
-        $resp = $this->url_request([],'user.balance.query');
+        $uri = $this->form_uri([],'user.balance.query');
+        $resp = http_request($uri, [], 'POST');
 
         if (empty($resp)) {
             return [false, '系统错误'];
@@ -167,7 +167,7 @@ class RefillPhone extends refill\IRefillPhone
             {
                 return [false, '系统错误'];
             }
-            elseif ($resp['code'] == 'SUCCESS')
+            elseif ($resp['code'] === 'SUCCESS')
             {
                 return [true, $resp['balance']];
             }
@@ -183,12 +183,14 @@ class RefillPhone extends refill\IRefillPhone
         $userId = config::UserId;
         $api_key = config::ApiKey;
         $content = "service={$get_params['service']}&userId={$userId}&ts={$get_params['ts']}&";
-        if(!empty($params)) {
+        if(!empty($params))
+        {
             foreach ($params as $key => $value){
                 $content .= "{$key}={$value}&";
             }
             $content = rtrim($content, '&');
         }
+
         $content .= "&key={$api_key}";
         return strtoupper(md5($content));
     }

+ 3 - 3
helper/refill/api/xyz/guochuang_nation/RefillPhone.php

@@ -74,7 +74,7 @@ class RefillPhone extends refill\IRefillPhone
             $code = $resp['code'];
             if (empty($resp)) {
                 return [false, '系统错误', true];
-            } elseif ($code == 'SUCCESS') {
+            } elseif ($code === 'SUCCESS') {
                 return [true, $resp['id'], false];
             } elseif (in_array($code, config::ORDER_ERR_CODE)) {
                 return [false, $code, false];
@@ -110,7 +110,7 @@ class RefillPhone extends refill\IRefillPhone
             {
                 return [false, '系统错误'];
             }
-            elseif ($code == 'SUCCESS')
+            elseif ($code === 'SUCCESS')
             {
                 $status = $resp['status'];
 
@@ -153,7 +153,7 @@ class RefillPhone extends refill\IRefillPhone
             {
                 return [false, '系统错误'];
             }
-            elseif ($resp['code'] == 'SUCCESS')
+            elseif ($resp['code'] === 'SUCCESS')
             {
                 return [true, $resp['balance']];
             }

+ 12 - 12
test/TestRefill.php

@@ -704,15 +704,15 @@ class TestRefill extends TestCase
     public function testGuochuang()
     {
         $providers = $this->getProvider('guochuang');
-//        $resp = $providers->add(13699279618, 4, 5, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+        $resp = $providers->add(13699279618, 4, 5, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
 //        $resp = $providers->query(['order_sn' => '82951628231038096078']);
-        $resp = $providers->balance();
+//        $resp = $providers->balance();
 //        $body = '{"account":"18074608795","evidence":"1000000083421080614310024563","evidenceType":"","id":"D2021080614235942044","inTime":"2021/08/06 14:26:22","money":"10","outerId":"82951628231038096078","status":"SUCCESS"}';
 //        $params['ts'] = 1628231182;
 //        $params['sign'] = '545F7024870B145915934CA36C6D341E';
 //        $params['body'] = $body;
 //        refill\RefillFactory::instance()->notify('guochuang', $params);
-        [$goods_id, $price] = $providers->goods(2, 10, 4, 1, []);
+//        [$goods_id, $price] = $providers->goods(2, 10, 4, 1, []);
     }
 
     public function testXianghongrui()
@@ -941,18 +941,18 @@ class TestRefill extends TestCase
     public function testGuochuang_nation()
     {
         $providers = $this->getProvider('guochuang_nation');
-//        $resp = $providers->add(18500608333, 5, 1, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
+        $resp = $providers->add(18500608333, 5, 1, ['order_sn' => $this->make_sn(), 'regin_no' => 1]);
 
 //        $resp = $providers->query(['order_sn' => '4372390688043259849812']);
-        $resp = $providers->balance();
+//        $resp = $providers->balance();
 
-        $body = '{"account":"18500608333","evidence":"N/A","evidenceType":"","id":"D2021090718185107657","inTime":"2021/09/07 18:19:05","money":"1","outerId":"65261631009929751933","status":"SUCCESS"}';
-        $params['ts'] = 1631009945;
-        $params['sign'] = 'C53F921EB5573EF4D0C757C5B5D4185D';
-        $params['body'] = $body;
-        $providers = $this->getProvider('guochuang_nation','RefillCallBack');
-        $ret = $providers->verify($params);
-        $resp = $providers->notify($params);
+//        $body = '{"account":"18500608333","evidence":"N/A","evidenceType":"","id":"D2021090718185107657","inTime":"2021/09/07 18:19:05","money":"1","outerId":"65261631009929751933","status":"SUCCESS"}';
+//        $params['ts'] = 1631009945;
+//        $params['sign'] = 'C53F921EB5573EF4D0C757C5B5D4185D';
+//        $params['body'] = $body;
+//        $providers = $this->getProvider('guochuang_nation','RefillCallBack');
+//        $ret = $providers->verify($params);
+//        $resp = $providers->notify($params);
     }
 
     public function testTianyanman()