stanley-king 1 năm trước cách đây
mục cha
commit
fb784463ce
3 tập tin đã thay đổi với 165 bổ sung22 xóa
  1. 125 18
      mapi/api/ctcard/CTCard.php
  2. 1 1
      mapi/api/ctcard/IOpenCard.php
  3. 39 3
      test/mapi/TestCTCard.php

+ 125 - 18
mapi/api/ctcard/CTCard.php

@@ -6,6 +6,8 @@ namespace mapi;
 require_once(BASE_MAPI_PATH . '/api/ctcard/config.php');
 require_once(BASE_MAPI_PATH . '/api/ctcard/IOpenCard.php');
 
+use Log;
+
 class CTCard implements IOpenCard
 {
     private function head($method) : array
@@ -46,63 +48,168 @@ class CTCard implements IOpenCard
     }
 
 
-    public function fraud_check($biz, &$net_errno = 0) : array
+    private function request($head_method,$biz,&$net_errno)
     {
-        $params['head'] = $this->head("fraudCheck");
+        $params['head'] = $this->head($head_method);
         $params['biz'] = $biz;
         $requestParameters = json_encode($params,JSON_UNESCAPED_UNICODE);
         $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
 
         if (empty($resp)) {
-            return [false, '网络错误'];
+            return [false, '网络错误',''];
         }
         else
         {
             $resp = json_decode($resp, true);
-            if(empty($resp["biz"])){
-                $err = $resp["head"]["err"];
-                return [false, $err];
-            }
-            $code = $resp["biz"]["code"];
-            $codeMessage = $resp["biz"]["codeMessage"];
-            if ($code == 0){ // 成功
-                return [true, $codeMessage];
-            }else { // 失败
-                return [false, $codeMessage];
+
+            Log::record($resp, Log::DEBUG);
+
+            if (empty($resp)) {
+                return [false, 'Net Error.',''];
             }
+
+            $head = $resp['head'] ?? [];
+            $biz  = $resp['biz'] ?? [];
+
+            return [true,$head,$biz];
         }
     }
 
+
+    public function fraud_check($biz) : array
+    {
+        [$succ, $head, $biz] = $this->request('fraudCheck', $biz, $net_errno);
+
+
+    }
+
     public function number_list($biz, &$net_errno = 0) : array
     {
         $params['head'] = $this->head("qryNbrList");
         $params['biz'] = $biz;
-        $requestParameters = json_encode($params);
+        $requestParameters = json_encode($params, JSON_UNESCAPED_UNICODE);
         $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
-
         return $resp;
     }
 
     public function address_delivery($biz, &$net_errno = 0) : array
     {
+        $callBack = function ($resp)
+        {
+            $resp = json_decode($resp, true);
+            $err = $resp["head"]["err"];
+            $code = $resp["head"]["code"];
+            if(empty($resp["biz"])){
+                return [$err, $code, []];
+            }
+            return [$err, $code, $resp];
+        };
+
         $params['head'] = $this->head("qryReceiveAddr");
         $params['biz'] = $biz;
-        $requestParameters = json_encode($params);
+        $requestParameters = json_encode($params, JSON_UNESCAPED_UNICODE);
         $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
         if (empty($resp)) {
             return [false, '网络错误'];
         }
         else
         {
+            list($err, $code, $response) = $callBack($resp);
+            if ($code == 0){ // 成功
+                return [true, "成功", $response];
+            }else { // 失败
+                return [false, $err];
+            }
+        }
+    }
+
+    public function broadband_address_list($biz, &$net_errno = 0) : array
+    {
+        $callBack = function ($resp)
+        {
             $resp = json_decode($resp, true);
             $err = $resp["head"]["err"];
+            $code = $resp["head"]["code"];
             if(empty($resp["biz"])){
+                return [$err, $code, []];
+            }
+            return [$err, $code, $resp];
+        };
+
+        $params['head'] = $this->head("qryAddressInfo");
+        $params['biz'] = $biz;
+        $requestParameters = json_encode($params, JSON_UNESCAPED_UNICODE);
+        $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            list($err, $code, $response) = $callBack($resp);
+            if ($code == 0){ // 成功
+                return [true, "成功", $response];
+            }else { // 失败
+                return [false, $err];
+            }
+        }
+    }
+
+    public function broadband_address_resource_query($biz, &$net_errno = 0) : array
+    {
+        $callBack = function ($resp)
+        {
+            $resp = json_decode($resp, true);
+            $err = $resp["head"]["err"];
+            $code = $resp["head"]["code"];
+            if(empty($resp["biz"])){
+                return [$err, $code, []];
+            }
+            return [$err, $code, $resp];
+        };
+
+        $params['head'] = $this->head("getAddressCover");
+        $params['biz'] = $biz;
+        $requestParameters = json_encode($params, JSON_UNESCAPED_UNICODE);
+        $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            list($err, $code, $response) = $callBack($resp);
+            if ($code == 0){ // 成功
+                return [true, "成功", $response];
+            }else { // 失败
                 return [false, $err];
             }
+        }
+    }
+
+    public function logistics_path_query($biz, &$net_errno = 0) : array
+    {
+        $callBack = function ($resp)
+        {
+            $resp = json_decode($resp, true);
+            $err = $resp["head"]["err"];
             $code = $resp["head"]["code"];
+            if(empty($resp["biz"])){
+                return [$err, $code, []];
+            }
+            return [$err, $code, $resp];
+        };
+
+        $params['head'] = $this->head("getAddressCover");
+        $params['biz'] = $biz;
+        $requestParameters = json_encode($params, JSON_UNESCAPED_UNICODE);
+        $resp = http_post_data(config::production_env['DcoosExternalNetwork'], $requestParameters , config::HeaderProduction, $net_errno);
+        if (empty($resp)) {
+            return [false, '网络错误'];
+        }
+        else
+        {
+            list($err, $code, $response) = $callBack($resp);
             if ($code == 0){ // 成功
-                $addrList = $resp["biz"]['addrList'];
-                return [true, "成功", $addrList];
+                return [true, "成功", $response];
             }else { // 失败
                 return [false, $err];
             }

+ 1 - 1
mapi/api/ctcard/IOpenCard.php

@@ -4,6 +4,6 @@ namespace mapi;
 
 interface IOpenCard
 {
-    public function fraud_check($data, &$net_errno) : array;
+    public function fraud_check($biz) : array;
 }
 

+ 39 - 3
test/mapi/TestCTCard.php

@@ -58,8 +58,7 @@ class TestCTCard extends TestCase
     {
         $x = date("ymdhm", time());
 
-        $guider = function (): string
-        {
+        $guider = function (): string {
             $str = md5(uniqid(mt_rand(), true));
             $uuid = substr($str, 0, 8);
             $uuid .= substr($str, 8, 4);
@@ -68,10 +67,47 @@ class TestCTCard extends TestCase
             $uuid .= substr($str, 20, 12);
             return $uuid;
         };
-        $make_sn = function () use ($guider){
+        $make_sn = function () use ($guider) {
             return config::SYS_CODE . config::APP_CODE . date("ymdhm", time()) . $guider();
         };
 
         $y = $make_sn();
     }
+
+    public function testBroadbandAddressList()
+    {
+        $ctcard = new CTCard();
+        // biz
+        $params = [
+            "areaCode" => "89801",
+            "areaName" => "秀英",
+            "endCode" => "10",
+            "fromCode" => "1"
+        ];
+
+        $ctcard->broadband_address_list($params);
+    }
+
+
+    public function testBroadbandAddressResourceQuery()
+    {
+        $ctcard = new CTCard();
+        // biz
+        $params = [
+            "addrId" => "19631954"
+        ];
+        $ctcard->broadband_address_resource_query($params);
+    }
+
+    public function testLogisticsPathQuery()
+    {
+        $ctcard = new CTCard();
+        // biz
+        $params = [
+            "orderCode" => "DQ201909260000112355670197",
+            "logisticNbr" => "JDV003703415445"
+        ];
+
+        $ctcard->logistics_path_query($params);
+    }
 }