diff --git a/app/Utils/API/Rocketgo.php b/app/Utils/API/Rocketgo.php index af6cfc1..5f31ddd 100644 --- a/app/Utils/API/Rocketgo.php +++ b/app/Utils/API/Rocketgo.php @@ -15,7 +15,7 @@ class Rocketgo /** * TOKEN */ - protected static $token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFlMTRlZWQ3LTEyODUtNGFjNi1hMzFhLTFlNWQ5OTEzMTJhYSJ9.BJgOhw1VKX1i9VfYKLIzF1zXUZMi4idO9Sb-p6p_rMKJanmt4is9slky7SqvSEXqhJ6USMGs2wqMY3tYJrH-hw"; + protected static $token = null; protected static $baseurl = "https://dx1.rocketgo.vip"; // URL前缀 @@ -43,6 +43,19 @@ class Rocketgo } return self::$client; } + // /** + // * 获取 token + // * 用于复用 客户端常驻内存 + // * + // * @return object + // */ + // protected static function get_token() + // { + // if (self::$token == null) { + // self::$token = + // } + // return self::$token; + // } /** * 获取 base64 图形验证码 @@ -152,8 +165,10 @@ class Rocketgo if ($responseData['code'] == 200) { self::$token = $responseData['token']; return $responseData['token']; + }else{ + Log::error("登录失败 未知错误: " . json_encode($responseData)); } - return $responseData; + // return $responseData; } catch (\Exception $e) { Log::error("登录失败: " . $e->getMessage()); } @@ -172,14 +187,14 @@ class Rocketgo * * @return void */ - protected static function test_login() + public static function test_login() { $client = self::get_client(); // 创建 Guzzle 客户端 try { // 发送 GET 请求 $response = $client->get("https://dx1.rocketgo.vip/prod-api2/biz/account/getLoginUserInfo", [ 'headers' => [ - 'Authorization' => self::$token, + 'Authorization' => 'Bearer ' . self::$token, 'Accept' => 'application/json', // 设置其他头信息 ] ]); @@ -187,10 +202,16 @@ class Rocketgo // 获取响应体内容 $body = $response->getBody(); $responseData = json_decode($body, true); - if ($responseData['code'] == 401) { - Log::info("登录过期需要重新登录"); - self::login('h102067452', 'yBQnfuBShGl1MTBN'); + // var_dump($responseData); + if(!empty($responseData['code'])){ + if ($responseData['code'] == 401) { + Log::info("登录过期需要重新登录"); + self::login('h102067452', 'yBQnfuBShGl1MTBN'); } + }else{ + Log::info("登录没有过期可以继续使用token"); + } + } catch (\Exception $e) { Log::error("检测登录是否过期失败: " . $e->getMessage()); }