diff --git a/Cunkebao/src/pages/mobile/scenarios/plan/list/components/AccountListModal.tsx b/Cunkebao/src/pages/mobile/scenarios/plan/list/components/AccountListModal.tsx index 0f4217c1..322bf0ae 100644 --- a/Cunkebao/src/pages/mobile/scenarios/plan/list/components/AccountListModal.tsx +++ b/Cunkebao/src/pages/mobile/scenarios/plan/list/components/AccountListModal.tsx @@ -149,7 +149,7 @@ const AccountListModal: React.FC = ({
{account.userinfo.nickname || account.userinfo.alias || - `账号${account.id}`} + `账号${account.phone || account.id}`}
{account.userinfo.wechatId || "未绑定微信号"} diff --git a/Cunkebao/src/pages/mobile/scenarios/plan/list/components/OreadyAdd.tsx b/Cunkebao/src/pages/mobile/scenarios/plan/list/components/OreadyAdd.tsx index fa6e1853..66f8e5e6 100644 --- a/Cunkebao/src/pages/mobile/scenarios/plan/list/components/OreadyAdd.tsx +++ b/Cunkebao/src/pages/mobile/scenarios/plan/list/components/OreadyAdd.tsx @@ -137,7 +137,7 @@ const AccountListModal: React.FC = ({
{account.userinfo.nickname || account.userinfo.alias || - `账号${account.id}`} + `账号${account.phone || account.id}`}
{account.userinfo.wechatId || "未绑定微信号"} diff --git a/Server/application/api/controller/WebSocketController.php b/Server/application/api/controller/WebSocketController.php index e1e97bf5..bac7fd2a 100644 --- a/Server/application/api/controller/WebSocketController.php +++ b/Server/application/api/controller/WebSocketController.php @@ -448,6 +448,43 @@ class WebSocketController extends BaseController return json_encode(['code' => 400, 'msg' => '资源信息格式错误,应为数组']); } + // 判断snsUrls是否已经是远程图片(http/https) + $allRemoteUrls = true; + foreach ($data['snsUrls'] as $url) { + if (empty($url)) { + continue; + } + // 检查URL是否以http://或https://开头 + if (!preg_match('/^https?:\/\//i', $url)) { + $allRemoteUrls = false; + break; + } + } + + // 如果全部都是远程URL,直接使用,不需要通过WebSocket下载 + if ($allRemoteUrls && !empty($data['snsUrls'])) { + $urls = json_encode($data['snsUrls'], 256); + + // 上传图片到OSS + $ossUrls = $this->uploadMomentImagesToOss($data['snsUrls'], $data['snsId']); + + // 更新数据库:保存原始URL和OSS URL,并标记已上传 + $updateData = [ + 'resUrls' => $urls, + 'isOssUploaded' => 1, // 标识已上传到OSS + 'update_time' => time() + ]; + + // 如果有OSS URL,保存到ossUrls字段 + if (!empty($ossUrls)) { + $updateData['ossUrls'] = json_encode($ossUrls, 256); + } + Db::table('s2_wechat_moments')->where('snsId', $data['snsId'])->update($updateData); + + return json_encode(['code' => 200, 'msg' => '获取朋友圈资源链接成功(已为远程URL)', 'data' => ['urls' => $data['snsUrls']]]); + } + + // 如果不是远程URL,需要通过WebSocket下载 // 检查连接状态 if (!$this->isConnected) { $this->connect(); @@ -659,6 +696,7 @@ class WebSocketController extends BaseController $dataToSave['wechatAccountId'] = $wechatAccountId; $dataToSave['wechatFriendId'] = $wechatFriendId ?? 0; $dataToSave['create_time'] = time(); + $dataToSave['ossUrls'] = json_encode([],256); $dataToSave['isOssUploaded'] = 0; // 新记录默认为未上传 $res = WechatMoments::create($dataToSave); } @@ -1114,4 +1152,25 @@ class WebSocketController extends BaseController } + + + public function ttttt($data = []) + { + try { + $params = [ + "chatroomOperateType" => $data['chatroomOperateType'], + "cmdType" => "CmdChatroomOperate", + "seq" => time(), + "wechatAccountId" => $data['wechatAccountId'], + "wechatChatroomId" => $data['wechatChatroomId'] + ]; + $message = $this->sendMessage($params,false); + return json_encode(['code' => 200, 'msg' => '234', 'data' => $message]); + } catch (\Exception $e) { + Log::error('修改群信息异常: ' . $e->getMessage()); + return json_encode(['code' => 500, 'msg' => '567567: ' . $e->getMessage()]); + } + } + + } \ No newline at end of file diff --git a/Server/application/command.php b/Server/application/command.php index ce06453b..061fb69b 100644 --- a/Server/application/command.php +++ b/Server/application/command.php @@ -27,6 +27,7 @@ return [ 'allotrule:autocreate' => 'app\command\AutoCreateAllotRulesCommand', // 自动创建分配规则 √ 'content:collect' => 'app\command\ContentCollectCommand', // 内容采集任务 √ 'moments:collect' => 'app\command\WechatMomentsCommand', // 朋友圈采集任务 + 'own:moments:collect' => 'app\command\OwnMomentsCollectCommand', // 采集在线微信账号自己的朋友圈 'switch:friends' => 'app\command\SwitchFriendsCommand', 'call-recording:list' => 'app\command\CallRecordingListCommand', // 通话记录列表 √ 'sync:wechatData' => 'app\command\SyncWechatDataToCkbTask', // 同步微信数据到存客宝 diff --git a/Server/application/command/OwnMomentsCollectCommand.php b/Server/application/command/OwnMomentsCollectCommand.php new file mode 100644 index 00000000..846f011c --- /dev/null +++ b/Server/application/command/OwnMomentsCollectCommand.php @@ -0,0 +1,51 @@ +setName('own:moments:collect') + ->setDescription('采集在线微信账号自己的朋友圈'); + } + + protected function execute(Input $input, Output $output) + { + $output->writeln('开始处理自己朋友圈采集任务...'); + + try { + // 将任务添加到队列 + $this->addToQueue(); + + $output->writeln('自己朋友圈采集任务已添加到队列'); + } catch (\Exception $e) { + Log::error('自己朋友圈采集任务添加失败:' . $e->getMessage()); + $output->writeln('自己朋友圈采集任务添加失败:' . $e->getMessage()); + return false; + } + + return true; + } + + /** + * 添加任务到队列 + */ + protected function addToQueue() + { + $data = [ + 'timestamp' => time() + ]; + + // 添加到队列,设置任务名为 own_moments_collect + Queue::push(OwnMomentsCollectJob::class, $data, 'own_moments_collect'); + } +} + diff --git a/Server/application/job/OwnMomentsCollectJob.php b/Server/application/job/OwnMomentsCollectJob.php new file mode 100644 index 00000000..931bdde6 --- /dev/null +++ b/Server/application/job/OwnMomentsCollectJob.php @@ -0,0 +1,159 @@ +processOwnMomentsCollect($data, $job->attempts())) { + $job->delete(); + Log::info('自己朋友圈采集任务执行成功'); + } else { + if ($job->attempts() > 3) { + // 超过重试次数,删除任务 + Log::error('自己朋友圈采集任务执行失败,已超过重试次数'); + $job->delete(); + } else { + // 任务失败,重新放回队列 + Log::warning('自己朋友圈采集任务执行失败,重试次数:' . $job->attempts()); + $job->release(Config::get('queue.failed_delay', 10)); + } + } + } catch (\Exception $e) { + // 出现异常,记录日志 + Log::error('自己朋友圈采集任务异常:' . $e->getMessage()); + if ($job->attempts() > 3) { + $job->delete(); + } else { + $job->release(Config::get('queue.failed_delay', 10)); + } + } + } + + /** + * 处理自己朋友圈采集 + * @param array $data 任务数据 + * @param int $attempts 重试次数 + * @return bool + */ + protected function processOwnMomentsCollect($data, $attempts) + { + try { + // 获取在线微信账号列表(只获取在线微信) + $onlineWechatAccounts = $this->getOnlineWechatAccounts(); + + if (empty($onlineWechatAccounts)) { + Log::info('没有在线微信账号,跳过朋友圈采集'); + return true; + } + + Log::info('找到 ' . count($onlineWechatAccounts) . ' 个在线微信账号,开始采集朋友圈'); + + // 获取API账号配置 + $username = Env::get('api.username2', ''); + $password = Env::get('api.password2', ''); + + if (empty($username) || empty($password)) { + Log::error('API账号配置缺失,无法执行朋友圈采集'); + return false; + } + + // 获取账号ID + $toAccountId = Db::name('users')->where('account', $username)->value('s2_accountId'); + if (empty($toAccountId)) { + Log::error('未找到API账号对应的账号ID'); + return false; + } + + $successCount = 0; + $failCount = 0; + + // 遍历每个在线微信账号,采集自己的朋友圈 + foreach ($onlineWechatAccounts as $account) { + try { + $wechatAccountId = $account['id']; + $wechatId = $account['wechatId']; + + Log::info("开始采集微信账号 {$wechatId} (ID: {$wechatAccountId}) 的朋友圈"); + + // 创建WebSocket控制器实例 + $webSocket = new WebSocketController([ + 'userName' => $username, + 'password' => $password, + 'accountId' => $toAccountId + ]); + + // 采集自己的朋友圈(wechatFriendId传0或空,表示采集自己的朋友圈) + $result = $webSocket->getMoments([ + 'wechatAccountId' => $wechatAccountId, + 'wechatFriendId' => 0, // 0表示采集自己的朋友圈 + 'count' => 10 // 每次采集10条 + ]); + + $resultData = json_decode($result, true); + if (!empty($resultData) && $resultData['code'] == 200) { + $successCount++; + Log::info("微信账号 {$wechatId} 朋友圈采集成功"); + } else { + $failCount++; + Log::warning("微信账号 {$wechatId} 朋友圈采集失败:" . ($resultData['msg'] ?? '未知错误')); + } + + // 避免请求过于频繁,每个账号之间稍作延迟 + usleep(500000); // 延迟0.5秒 + + } catch (\Exception $e) { + $failCount++; + Log::error("采集微信账号 {$account['wechatId']} 朋友圈异常:" . $e->getMessage()); + continue; + } + } + + Log::info("自己朋友圈采集任务完成,成功:{$successCount},失败:{$failCount}"); + return true; + + } catch (\Exception $e) { + Log::error('自己朋友圈采集处理异常:' . $e->getMessage()); + return false; + } + } + + /** + * 获取在线微信账号列表 + * @return array + */ + protected function getOnlineWechatAccounts() + { + try { + // 查询在线微信账号(deviceAlive=1 且 wechatAlive=1) + $accounts = Db::table('s2_wechat_account') + ->where('deviceAlive', 1) + ->where('wechatAlive', 1) + ->field('id, wechatId, nickname, alias') + ->select(); + + return $accounts ?: []; + } catch (\Exception $e) { + Log::error('获取在线微信账号列表失败:' . $e->getMessage()); + return []; + } + } +} + diff --git a/Server/crontab_tasks.md b/Server/crontab_tasks.md index 417e1f7e..708b4074 100644 --- a/Server/crontab_tasks.md +++ b/Server/crontab_tasks.md @@ -172,6 +172,9 @@ crontab -l # 客服评分 0 2 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think wechat:calculate-score >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/calculate_score.log 2>&1 +# 采集客服自己的朋友圈 +0 30 * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think own:moments:collect >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/own_moments_collect.log 2>&1 + # 每分钟执行一次调度器(调度器内部会自动判断哪些任务需要执行)