Files
im-demo-server/app/Services/GatewayWorker/ImService.php
2025-06-26 10:17:21 +08:00

34 lines
855 B
PHP

<?php
namespace App\Services\GatewayWorker;
use App\Enum\MessageTypeEnum;
use App\Services\Base\BaseService;
class ImService extends BaseService
{
public function bindClientIdByUserId($clientId)
{
if (empty($clientId)) {
throw new \Exception('clientId不能为空');
}
GatewayClientService::getInstance()->init()->bindUser($clientId, $this->userId);
return ['绑定成功'];
}
public function sendMessage($data, $type = MessageTypeEnum::Text->value)
{
$data['message_type'] = MessageTypeEnum::from($type)->description();
GatewayClientService::getInstance()->init()->sendToUser(
$this->userId === 1? 2: 1,
$this->userId,
$this->userInfo['nick_name'],
$data['content'],
);
return ['发送成功'];
}
}