34 lines
855 B
PHP
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 ['发送成功'];
|
|
}
|
|
}
|