From 754607ca7a5ccf79c98bbebff84b0f218b62a45e Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Sat, 1 Jul 2023 12:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20guzzle=20http=20=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20curl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Support/WHMCS.php | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/app/Support/WHMCS.php b/app/Support/WHMCS.php index 8654d56..5329335 100644 --- a/app/Support/WHMCS.php +++ b/app/Support/WHMCS.php @@ -2,6 +2,7 @@ namespace App\Support; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; class WHMCS @@ -67,19 +68,11 @@ private function request($action, $params = []): ?array ], $params); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $this->url . '/includes/api.php'); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt( - $ch, - CURLOPT_POSTFIELDS, - http_build_query($params) - ); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($ch); - curl_close($ch); + $http = Http::asForm()->post($this->url . '/includes/api.php', $params)->throw(); + + $response = $http->body(); + $json = $http->json(); - $json = json_decode($response, true); if (is_null($json)) { Log::error('WHMCS response is not valid JSON', [$response]); @@ -104,19 +97,11 @@ public function api($action, $params = []): ?array $url = $this->url . '/modules/addons/PortIOInvoice/api/' . $action . '.php'; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt( - $ch, - CURLOPT_POSTFIELDS, - http_build_query($params) - ); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - $response = curl_exec($ch); - $json = json_decode($response, true); - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); + $http = Http::asForm()->post($url, $params)->throw(); + + $code = $http->status(); + $response = $http->body(); + $json = $http->json(); if (is_null($json)) { Log::error('WHMCS response is not valid JSON', [$url, $code, $response]);