Quellcode durchsuchen

快递信息同步

ANG YU vor 5 Jahren
Ursprung
Commit
a5a6959e36
2 geänderte Dateien mit 13 neuen und 26 gelöschten Zeilen
  1. 3 13
      app/Services/LogisticYDService.php
  2. 10 13
      app/library/zop/ZopClient.php

+ 3 - 13
app/Services/LogisticYDService.php

@@ -64,12 +64,7 @@ class LogisticYDService
             'req-time' => now()->timestamp,
             "Content-Type" => "application/json"
         ];
-        try {
-            $response = Http::withHeaders($headers)->withBody($json_body, 'application/json')->post($this->url);
-        } catch (\Exception $e) {
-            LogService::log(LogisticYDService::class, "韵达注册接口异常", $json_body);
-            $response = null;
-        }
+        $response = Http::withHeaders($headers)->withBody($json_body, 'application/json')->post($this->url);
         return json_decode($response);
     }
 
@@ -88,18 +83,13 @@ class LogisticYDService
             'req-time' => now()->timestamp,
             "Content-Type" => "application/json"
         ];
-        try{
-            $response = Http::withHeaders($headers)->withBody(json_encode($body, JSON_UNESCAPED_UNICODE), 'application/json')->post($this->url);
-        }catch(\Exception $e){
-            LogService::log(LogisticYDService::class, "韵达路由查询接口异常", json_encode($body, JSON_UNESCAPED_UNICODE), 'application/json');
-            return null;
-        }
+        $response = Http::withHeaders($headers)->withBody(json_encode($body, JSON_UNESCAPED_UNICODE), 'application/json')->post($this->url);
         return json_decode($response->body());
     }
 
     public function format($nativeResponse)
     {
-        if (is_null($nativeResponse)|| $nativeResponse->code != '0000' || $nativeResponse->data->result=="false") {
+        if (is_null($nativeResponse) || $nativeResponse->code != '0000' || $nativeResponse->data->result == "false") {
             return [];
         } else {
             $nativeData = $nativeResponse->data;

+ 10 - 13
app/library/zop/ZopClient.php

@@ -2,6 +2,7 @@
 
 
 namespace App\library\zop;
+
 use App\Jobs\LogisticZopSync;
 use App\library\zop\ZopHttpUtil;
 use App\Services\LogService;
@@ -12,6 +13,7 @@ class ZopClient
     private $zopProperties;
 
     private $httpClient;
+
     /**
      * ZopClient constructor.
      * @param $zopProperties
@@ -24,7 +26,7 @@ class ZopClient
 
     public function execute($zopRequest)
     {
-        if($zopRequest->getBody()==null) {
+        if ($zopRequest->getBody() == null) {
             $url = $zopRequest->getUrl();
             $params = $zopRequest->getParams();
             $fixedParams = array();
@@ -37,9 +39,9 @@ class ZopClient
             }
             $str_to_digest = "";
             foreach ($fixedParams as $k => $v) {
-                $str_to_digest = $str_to_digest .$k ."=" .$v ."&";
+                $str_to_digest = $str_to_digest . $k . "=" . $v . "&";
             }
-            $str_to_digest = substr($str_to_digest, 0, -1) .$this->zopProperties->getKey();
+            $str_to_digest = substr($str_to_digest, 0, -1) . $this->zopProperties->getKey();
             $data_digest = base64_encode(md5($str_to_digest, TRUE));
             $headers = array(
                 "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
@@ -52,16 +54,11 @@ class ZopClient
             $body = $zopRequest->getBody();
             $str_to_digest = $body . $this->zopProperties->getKey();
             $data_digest = base64_encode(md5($str_to_digest, TRUE));
-            try {
-                $response = Http::withHeaders([
-                    'Content-Type' => 'application/json; charset=UTF-8',
-                    'x-companyid' => $this->zopProperties->getCompanyid(),
-                    'x-datadigest' => $data_digest,
-                ])->withBody(json_encode((array)json_decode($body), JSON_UNESCAPED_UNICODE), 'application/json')->post($url);
-            } catch (\Exception $e) {
-                LogService::log(LogisticZopSync::class, "中通接口请求出错", json_encode((array)json_decode($body), JSON_UNESCAPED_UNICODE));
-                return null;
-            }
+            $response = Http::withHeaders([
+                'Content-Type' => 'application/json; charset=UTF-8',
+                'x-companyid' => $this->zopProperties->getCompanyid(),
+                'x-datadigest' => $data_digest,
+            ])->withBody(json_encode((array)json_decode($body), JSON_UNESCAPED_UNICODE), 'application/json')->post($url);
             return $response->body();
         }
     }