diff --git a/Server/application/api/controller/AutomaticAssign.php b/Server/application/api/controller/AutomaticAssign.php index 64be22e0..6ea68560 100644 --- a/Server/application/api/controller/AutomaticAssign.php +++ b/Server/application/api/controller/AutomaticAssign.php @@ -189,7 +189,7 @@ class AutomaticAssign extends BaseController $wechatFriendId = !empty($data['wechatFriendId']) ? $data['wechatFriendId'] : input('wechatFriendId', 0); $toAccountId = !empty($data['toAccountId']) ? $data['toAccountId'] : input('toAccountId', 0); $comment = !empty($data['comment']) ? $data['comment'] : input('comment', ''); - $notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', false); + $notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', 'false'); $optFrom = !empty($data['optFrom']) ? $data['optFrom'] : input('optFrom', 4); // 默认操作来源为4 // 参数验证 @@ -234,7 +234,6 @@ class AutomaticAssign extends BaseController } - public function multiAllotFriendToAccount($data = []){ // 获取授权token $authorization = $this->authorization; @@ -244,16 +243,15 @@ class AutomaticAssign extends BaseController $wechatFriendIds = !empty($data['wechatFriendIds']) ? $data['wechatFriendIds'] : input('wechatFriendIds', []); $toAccountId = !empty($data['toAccountId']) ? $data['toAccountId'] : input('toAccountId', 0); - $notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', false); - + $notifyReceiver = !empty($data['notifyReceiver']) ? $data['notifyReceiver'] : input('notifyReceiver', 'false'); // 参数验证 if (empty($wechatFriendIds)) { return json_encode(['code'=>500,'msg'=>'微信好友ID不能为空']); - } + } - if (empty($toAccountId)) { - return json_encode(['code'=>500,'msg'=>'目标账号ID不能为空']); - } + if (empty($toAccountId)) { + return json_encode(['code'=>500,'msg'=>'目标账号ID不能为空']); + } // 设置请求头 @@ -263,7 +261,6 @@ class AutomaticAssign extends BaseController // 发送请求 $url = $this->baseUrl . 'api/WechatFriend/multiAllotFriendToAccount?wechatFriendIds='.$wechatFriendIds.'&toAccountId='.$toAccountId.'¬ifyReceiver='.$notifyReceiver; $result = requestCurl($url, [], 'PUT', $header, 'json'); - if (empty($result)) { return json_encode(['code'=>200,'msg'=>'微信好友分配成功']); } else { diff --git a/Server/application/command/SwitchFriendsCommand.php b/Server/application/command/SwitchFriendsCommand.php index ffcc2098..488e39a2 100644 --- a/Server/application/command/SwitchFriendsCommand.php +++ b/Server/application/command/SwitchFriendsCommand.php @@ -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);