This commit is contained in:
2025-06-26 10:21:45 +08:00
parent 6604f4c6aa
commit 5c04064df1
2 changed files with 13 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ class BaseService
{
protected $userId;
protected $userInfo;
protected $gatewayClient;
/**
* @var mixed 单例实例,确保该类只有一个全局实例
*/

View File

@@ -8,6 +8,12 @@ use App\Services\Base\BaseService;
class ImService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->gatewayClient = GatewayClientService::getInstance()->init();
}
public function bindClientIdByUserId($clientId)
{
if (empty($clientId)) {
@@ -22,12 +28,17 @@ class ImService extends BaseService
public function sendMessage($data, $type = MessageTypeEnum::Text->value)
{
$data['message_type'] = MessageTypeEnum::from($type)->description();
GatewayClientService::getInstance()->init()->sendToUser(
$this->gatewayClient->sendToUser(
$this->userId === 1? 2: 1,
$this->userId,
$this->userInfo['nick_name'],
$data['content'],
);
$this->gatewayClient->broadcastMessage(
$this->userId,
$this->userInfo['nick_name'],
$data['content'],
);
return ['发送成功'];
}
}