测试
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user