diff --git a/app/Services/GatewayWorker/GatewayClientService.php b/app/Services/GatewayWorker/GatewayClientService.php index e1a60180..3bcece99 100644 --- a/app/Services/GatewayWorker/GatewayClientService.php +++ b/app/Services/GatewayWorker/GatewayClientService.php @@ -55,11 +55,12 @@ class GatewayClientService /** * 构建标准化消息 */ - protected function buildMessage(int $userId, string $name, string $text, string $type = 'received'): string + protected function buildMessage(int $userId, string $name, string $avatarColor, string $text, string $type = 'received'): string { $message = [ 'userId' => $userId, 'userName' => $name, + 'avatarColor' => $avatarColor, 'content' => $text, 'timestamp' => time(), // ISO 8601格式时间 'type' => $type @@ -71,18 +72,18 @@ class GatewayClientService /** * 发送消息给指定用户 */ - public function sendToUser(int $toUserId, int $fromUserId, string $fromUserName, string $msgData, string $type = 'chat'): void + public function sendToUser(int $toUserId, int $fromUserId, string $formUserAvatarColor, string $fromUserName, string $msgData, string $type = 'chat'): void { - $message = $this->buildMessage($fromUserId, $fromUserName, $msgData, $type); + $message = $this->buildMessage($fromUserId, $fromUserName, $formUserAvatarColor, $msgData, $type); Gateway::sendToUid($toUserId, $message); } /** * 广播消息给所有用户(可排除指定用户) */ - public function broadcastMessage(int $fromUserId, string $fromUserName, string $text, ?int $excludeUserId = null, string $type = 'chat'): void + public function broadcastMessage(int $fromUserId, string $formUserAvatarColor, string $fromUserName, string $text, ?int $excludeUserId = null, string $type = 'chat'): void { - $message = $this->buildMessage($fromUserId, $fromUserName, $text, $type); + $message = $this->buildMessage($fromUserId, $fromUserName, $formUserAvatarColor, $text, $type); $excludeList = $excludeUserId ? [$excludeUserId] : []; Gateway::sendToAll($message, null, $excludeList); diff --git a/app/Services/GatewayWorker/ImService.php b/app/Services/GatewayWorker/ImService.php index 191ff8e5..9002c8f0 100644 --- a/app/Services/GatewayWorker/ImService.php +++ b/app/Services/GatewayWorker/ImService.php @@ -28,22 +28,24 @@ class ImService extends BaseService public function sendMessage($data, $type = MessageTypeEnum::Text->value) { - $uids = [1,2,3]; - $uidsC = []; - foreach ($uids as $v) { - $uidsC[$v] = Gateway::getClientIdByUid($v); - } - ds($uidsC); +// $uids = [1,2,3]; +// $uidsC = []; +// foreach ($uids as $v) { +// $uidsC[$v] = Gateway::getClientIdByUid($v); +// } +// ds($uidsC); $data['message_type'] = MessageTypeEnum::from($type)->description(); $this->gatewayClient->sendToUser( $this->userId === 1? 2: 1, $this->userId, $this->userInfo['nick_name'], + $data['avatarColor'], $data['content'], ); $this->gatewayClient->broadcastMessage( $this->userId, $this->userInfo['nick_name'], + $data['avatarColor'], $data['content'], ); return ['发送成功'];