代码优化

This commit is contained in:
wong
2025-07-11 16:47:50 +08:00
parent 9193004c54
commit 66c6455a44
3 changed files with 13 additions and 40 deletions

View File

@@ -219,7 +219,8 @@ class WorkbenchAutoLikeJob
// 执行切换好友命令
$automaticAssign = new AutomaticAssign();
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true);
//存入缓存
artificialAllotWechatFriend($friend);
// 创建WebSocket链接
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
@@ -234,12 +235,7 @@ class WorkbenchAutoLikeJob
if (empty($moments) || count($moments) == 0) {
// 处理完毕切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈");
return;
}
@@ -263,19 +259,11 @@ class WorkbenchAutoLikeJob
}
// 处理完毕切换回原账号
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
} catch (\Exception $e) {
// 异常情况下也要确保切换回原账号
$automaticAssign = new AutomaticAssign();
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
$res = json_decode($res, true);
if($res == '无效路径或登录状态失效'){
artificialAllotWechatFriend($friend);
}
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
Log::error("处理好友 {$friend['friendId']} 朋友圈失败异常: " . $e->getMessage());
}
}