gatewayClient = GatewayClientService::getInstance()->init(); } 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) { // $uids = [1,2,3]; // $uidsC = []; // foreach ($uids as $v) { // $uidsC[$v] = Gateway::getClientIdByUid($v); // } // ds($uidsC); $data['message_type'] = MessageTypeEnum::from($type)->description(); $this->gatewayClient->sendToUser( $this->userId === 1? 2: 1, $this->userId, $data['avatarColor'], $this->userInfo['nick_name'], '单聊'. $data['content'], ); // $this->gatewayClient->broadcastMessage( // $this->userId, // $data['avatarColor'], // $this->userInfo['nick_name'], // '群发'. $data['content'], // ); return ['发送成功']; } }