userServiceClient->getTypeUserList(['type_id' => 10000]); // 获取 Swoole WebSocket Server 实例 $server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class); $redisClient = new RedisService(); if ($adminList && isset($adminList['data'])) { foreach ($adminList['data'] as $admin) { $fd = $redisClient->findFd((int)$admin['id']); if ($fd && $server->isEstablished((int)$fd)) { $server->push((int)$fd, json_encode($data)); } } } return true; } catch (\Throwable $e) { var_dump('发送消息错误: ' . $e->getMessage()); return false; } } public function sendUserMessage($data){ try { // 获取 Swoole WebSocket Server 实例 $server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class); $redisClient = new RedisService(); $fd = $redisClient->findFd((int)$data['user_id']); if ($fd && $server->isEstablished((int)$fd)) { $server->push((int)$fd, json_encode($data)); } } catch (\Throwable $e) { var_dump('发送消息错误: ' . $e->getMessage()); return false; } } public function sendOtherUserMessage($data){ try { // 获取 Swoole WebSocket Server 实例 $server = \Hyperf\Context\ApplicationContext::getContainer()->get(\Swoole\Server::class); $redisClient = new RedisService(); $data['user_id'] = json_decode($data['user_id'],true); // var_dump($data['user_id'],"====================%%%%%%%%%%%===="); if(is_array($data['user_id'])){ foreach($data['user_id'] as $user_id){ $fd = $redisClient->findFd((int)$user_id); if ($fd && $server->isEstablished((int)$fd)) { $server->push((int)$fd, json_encode($data)); } } } } catch (\Throwable $e) { var_dump('发送消息错误: ' . $e->getMessage()); return false; } } }