feat: 添加获取指定手机号状态的功能,优化登录状态检查逻辑

This commit is contained in:
lingling 2025-03-18 18:16:24 +08:00
parent f19bb0c01b
commit ca364fc3d5
2 changed files with 42 additions and 6 deletions
app
Utils/API
controller/api

View File

@ -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;
}
}

View File

@ -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;