优化代码
This commit is contained in:
@@ -220,24 +220,6 @@ class WorkbenchAutoLikeJob
|
||||
$automaticAssign = new AutomaticAssign();
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $toAccountId], true);
|
||||
|
||||
//记录切换好友
|
||||
$cacheKey = 'allotWechatFriend';
|
||||
$cacheFriend = $friend;
|
||||
$cacheFriend['time'] = time() + 120;
|
||||
$maxRetry = 5;
|
||||
$retry = 0;
|
||||
do {
|
||||
$cacheFriendData = Cache::get($cacheKey, []);
|
||||
// 去重:移除同friendId的旧数据
|
||||
$cacheFriendData = array_filter($cacheFriendData, function($item) use ($cacheFriend) {
|
||||
return $item['friendId'] !== $cacheFriend['friendId'];
|
||||
});
|
||||
$cacheFriendData[] = $cacheFriend;
|
||||
$success = Cache::set($cacheKey, $cacheFriendData);
|
||||
$retry++;
|
||||
} while (!$success && $retry < $maxRetry);
|
||||
|
||||
|
||||
// 创建WebSocket链接
|
||||
$webSocket = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]);
|
||||
|
||||
@@ -252,7 +234,12 @@ class WorkbenchAutoLikeJob
|
||||
|
||||
if (empty($moments) || count($moments) == 0) {
|
||||
// 处理完毕切换回原账号
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = json_decode($res, true);
|
||||
if($res == '无效路径或登录状态失效'){
|
||||
artificialAllotWechatFriend($friend);
|
||||
}
|
||||
|
||||
Log::info("好友 {$friend['friendId']} 没有需要点赞的朋友圈");
|
||||
return;
|
||||
}
|
||||
@@ -276,11 +263,19 @@ class WorkbenchAutoLikeJob
|
||||
}
|
||||
|
||||
// 处理完毕切换回原账号
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = json_decode($res, true);
|
||||
if($res == '无效路径或登录状态失效'){
|
||||
artificialAllotWechatFriend($friend);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 异常情况下也要确保切换回原账号
|
||||
$automaticAssign = new AutomaticAssign();
|
||||
$automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = $automaticAssign->allotWechatFriend(['wechatFriendId' => $friend['friendId'], 'toAccountId' => $friend['accountId']], true);
|
||||
$res = json_decode($res, true);
|
||||
if($res == '无效路径或登录状态失效'){
|
||||
artificialAllotWechatFriend($friend);
|
||||
}
|
||||
Log::error("处理好友 {$friend['friendId']} 朋友圈失败异常: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user