代码提交

This commit is contained in:
wong
2025-07-11 17:38:44 +08:00
parent 80b52ce8c9
commit ce4beab201
2 changed files with 16 additions and 15 deletions

View File

@@ -37,7 +37,13 @@ class SwitchFriendsCommand extends Command
$output->writeln('开始执行好友切换任务...');
do {
$friends = Cache::get($cacheKey, []);
//$friends = Cache::get($cacheKey, []);
$friends = [
['time' => 1111,'accountId' => 6222,'friendId' => 21075650],
['time' => 1111,'accountId' => 6222,'friendId' => 20112769],
];
$toSwitch = [];
foreach ($friends as $friend) {
@@ -65,25 +71,23 @@ class SwitchFriendsCommand extends Command
$friendId = !empty($friend['friendId']) ? $friend['friendId'] : $friend['id'];
$groupedByAccount[$accountId][] = $friendId;
}
// 对每个账号的好友进行20个为一组的分组
foreach ($groupedByAccount as $accountId => $accountFriends) {
$chunks = array_chunk($accountFriends, 20);
$output->writeln('账号 ' . $accountId . ' 共有 ' . count($accountFriends) . ' 个好友,分为 ' . count($chunks) . ' 组');
$accountSuccess = 0;
$accountFailed = 0;
foreach ($chunks as $chunkIndex => $chunk) {
$output->writeln('处理账号 ' . $accountId . ' 第 ' . ($chunkIndex + 1) . ' 组,共 ' . count($chunk) . ' 个好友');
try {
$friendIds = implode(',', $chunk);
$res = $automaticAssign->multiAllotFriendToAccount([
'wechatFriendIds' => $friendIds,
'toAccountId' => $accountId,
]);
$res = json_decode($res, true);
if ($res['code'] == 200){
$output->writeln('✓ 成功切换好友:' . $friendIds . ' 到账号:' . $accountId);