Files
im-demo-server/app/Services/GatewayWorker/ImService.php

34 lines
857 B
PHP
Raw Normal View History

2025-06-25 14:09:34 +08:00
<?php
namespace App\Services\GatewayWorker;
2025-06-26 09:56:14 +08:00
use App\Enum\MessageTypeEnum;
2025-06-25 16:12:51 +08:00
use App\Services\Base\BaseService;
class ImService extends BaseService
2025-06-25 14:09:34 +08:00
{
2025-06-25 16:12:51 +08:00
public function bindClientIdByUserId($clientId)
{
if (empty($clientId)) {
throw new \Exception('clientId不能为空');
}
GatewayClientService::getInstance()->init()->bindUser($clientId, $this->userId);
return ['绑定成功'];
}
2025-06-26 09:56:14 +08:00
public function sendMessage($data, $type = MessageTypeEnum::Text->value)
{
2025-06-26 10:05:04 +08:00
$data['message_type'] = MessageTypeEnum::from($type)->description();
2025-06-26 09:56:14 +08:00
GatewayClientService::getInstance()->init()->sendToUser(
$this->userId === 1? 2: 1,
2025-06-26 10:13:19 +08:00
$this->userId,
2025-06-26 10:10:02 +08:00
$this->userInfo['nick_name'],
2025-06-26 09:56:14 +08:00
json_encode($data),
);
return ['发送成功'];
}
2025-06-25 14:09:34 +08:00
}