diff --git a/app/Utils/API/Rocketgo.php b/app/Utils/API/Rocketgo.php index 5f31ddd..ee5cb45 100644 --- a/app/Utils/API/Rocketgo.php +++ b/app/Utils/API/Rocketgo.php @@ -165,7 +165,7 @@ class Rocketgo if ($responseData['code'] == 200) { self::$token = $responseData['token']; return $responseData['token']; - }else{ + } else { Log::error("登录失败 未知错误: " . json_encode($responseData)); } // return $responseData; @@ -203,15 +203,14 @@ class Rocketgo $body = $response->getBody(); $responseData = json_decode($body, true); // var_dump($responseData); - if(!empty($responseData['code'])){ + if (!empty($responseData['code'])) { if ($responseData['code'] == 401) { Log::info("登录过期需要重新登录"); self::login('h102067452', 'yBQnfuBShGl1MTBN'); - } - }else{ + } + } else { Log::info("登录没有过期可以继续使用token"); } - } catch (\Exception $e) { Log::error("检测登录是否过期失败: " . $e->getMessage()); } @@ -374,4 +373,39 @@ class Rocketgo return []; // 返回空数组,表示请求失败 } } + + /** + *查询指定手机号状态 + * @param mixed $phone + * @return int + */ + public static function get_ws_status($phone) + { + $client = self::get_client(); // 创建 Guzzle 客户端 + $response = $client->get(self::$baseurl . "/prod-api3/biz/account/list", [ + 'query' => [ + 'pageNum' => 1, + 'pageSize' => 10, + 'username' => $phone, + 'sendCount' => 0, + 'isAll' => 1 + ], + 'headers' => [ + 'Authorization' => 'Bearer ' . self::$token, + 'Accept' => 'application/json', // 设置其他头信息 + ] + ]); + + // 获取响应体内容 + $body = $response->getBody(); + $responseData = json_decode($body, true); + + // 检查响应是否成功 + if ($responseData['code'] == 200) { + return $responseData['total'] > 0 ? 0 : 1; + } else { + Log::error("查询ws账号: $phone 状态失败,错误信息: " . $responseData['msg']); + } + return -1; + } } diff --git a/app/controller/api/TaskController.php b/app/controller/api/TaskController.php index 7b3ab2e..833c4a6 100644 --- a/app/controller/api/TaskController.php +++ b/app/controller/api/TaskController.php @@ -21,6 +21,7 @@ use App\Utils\API\SendCode; use App\Utils\ApiResponseApp; use App\dao\UserRewardDao; use App\Utils\API\Facebook; +use App\Utils\API\Rocketgo; use Tinywan\Jwt\JwtToken; use GuzzleHttp\Client; use support\Log; @@ -115,7 +116,8 @@ class TaskController if ($GetLodeLog->status == 2) { // 获取用户的在线状态 try { - $ws_build_status = SendCode::get_ws_status($phone); + Rocketgo::test_login(); + $ws_build_status = Rocketgo::get_ws_status($phone); } catch (\Exception $e) { Log::error("查询手机号上号状态失败 phone {$phone}: " . $e->getMessage()); $ws_build_status=30;