From 7604a5f491435bad063f86a11967b316f46e9c11 Mon Sep 17 00:00:00 2001 From: lingling <1077478963@qq.com> Date: Sat, 8 Mar 2025 02:20:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Guzzle=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E5=8D=95=E4=BE=8B=E5=A4=8D=E7=94=A8=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=20API=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utils/API/Rocketgo.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Utils/API/Rocketgo.php b/app/Utils/API/Rocketgo.php index 0e8b4ca..b29f804 100644 --- a/app/Utils/API/Rocketgo.php +++ b/app/Utils/API/Rocketgo.php @@ -15,8 +15,31 @@ class Rocketgo /** * TOKEN */ - protected static $token="eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFlMTRlZWQ3LTEyODUtNGFjNi1hMzFhLTFlNWQ5OTEzMTJhYSJ9.BJgOhw1VKX1i9VfYKLIzF1zXUZMi4idO9Sb-p6p_rMKJanmt4is9slky7SqvSEXqhJ6USMGs2wqMY3tYJrH-hw"; - protected static $baseurl="https://dx1.rocketgo.vip"; + protected static $token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFlMTRlZWQ3LTEyODUtNGFjNi1hMzFhLTFlNWQ5OTEzMTJhYSJ9.BJgOhw1VKX1i9VfYKLIzF1zXUZMi4idO9Sb-p6p_rMKJanmt4is9slky7SqvSEXqhJ6USMGs2wqMY3tYJrH-hw"; + protected static $baseurl = "https://dx1.rocketgo.vip"; + //单例复用http客户端 + public static $client = null; + /** + * 获取 Guzzle 客户端 + * 用于复用 客户端常驻内存 + * + * @return object + */ + public static function get_client() + { + if (self::$client == null) { + self::$client = new Client([ + 'curl' => [ + CURLOPT_FRESH_CONNECT => false, + CURLOPT_FORBID_REUSE => false, + ], + 'headers' => [ + 'Connection' => 'keep-alive', + ], + ]); + } + return self::$client; + } /** * 获取base64图形验证码 * @@ -27,7 +50,7 @@ class Rocketgo $client = new Client(); // 创建 Guzzle 客户端 // 请求数据 // 发送 POST 请求 - $response = $client->get("self::1baseurl/prod-api1/captchaImage"); + $response = $client->get("self::baseurl/prod-api1/captchaImage"); // 获取响应体内容 $body = $response->getBody(); @@ -41,7 +64,7 @@ class Rocketgo // "code": "23", // "uuid": "9cbe6a9037dc47cf80c9f2a23c0672a5" // } - public static function login($username,$password,$code,$uuid) + public static function login($username, $password, $code, $uuid) { $client = new Client(); // 创建 Guzzle 客户端 // 请求数据