diff --git a/app/Amqp/Producer/ChatMessageProducer.php b/app/Amqp/Producer/ChatMessageProducer.php index 1991f6a..ed7cdc6 100644 --- a/app/Amqp/Producer/ChatMessageProducer.php +++ b/app/Amqp/Producer/ChatMessageProducer.php @@ -14,7 +14,6 @@ namespace App\Amqp\Producer; use App\Constants\SocketConstants; use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\Type; -use Hyperf\Utils\Str; /** * 消息生产者 diff --git a/app/Cache/FriendRemark.php b/app/Cache/FriendRemark.php index d67f72e..7e40b00 100644 --- a/app/Cache/FriendRemark.php +++ b/app/Cache/FriendRemark.php @@ -33,7 +33,7 @@ class FriendRemark extends HashRedis * @param int $friend_id 好友ID * @return string */ - public function read(int $user_id, int $friend_id) + public function read(int $user_id, int $friend_id): string { return $this->get($this->_flag($user_id, $friend_id)); } @@ -45,7 +45,7 @@ class FriendRemark extends HashRedis * @param int $friend_id 好友ID * @return string */ - private function _flag(int $user_id, int $friend_id) + private function _flag(int $user_id, int $friend_id): string { return "{$user_id}_{$friend_id}"; } diff --git a/app/Cache/LastMessage.php b/app/Cache/LastMessage.php index 57050af..106b287 100644 --- a/app/Cache/LastMessage.php +++ b/app/Cache/LastMessage.php @@ -34,7 +34,7 @@ class LastMessage extends HashRedis * @param int $receive 接收者ID * @return array */ - public function read(int $type, int $sender, int $receive) + public function read(int $type, int $sender, int $receive): array { $message = $this->get($this->flag($type, $sender, $receive)); diff --git a/app/Cache/ServerRunID.php b/app/Cache/ServerRunID.php index ac95a2b..9767278 100644 --- a/app/Cache/ServerRunID.php +++ b/app/Cache/ServerRunID.php @@ -4,6 +4,11 @@ namespace App\Cache; use App\Cache\Repository\HashRedis; +/** + * 服务运行ID - 缓存助手 + * + * @package App\Cache + */ class ServerRunID extends HashRedis { protected $prefix = 'SERVER_RUN_ID'; @@ -21,7 +26,7 @@ class ServerRunID extends HashRedis * @param int $type 获取类型[1:正在运行;2:已超时;3:所有] * @return array */ - public function getServerRunIdAll(int $type = 1) + public function getServerRunIdAll(int $type = 1): array { $arr = $this->all(); diff --git a/app/Cache/SocketFdBindUser.php b/app/Cache/SocketFdBindUser.php index 0490db4..bb6058e 100644 --- a/app/Cache/SocketFdBindUser.php +++ b/app/Cache/SocketFdBindUser.php @@ -44,7 +44,7 @@ class SocketFdBindUser extends HashGroupRedis * @param string $run_id 服务运行ID(默认当前服务ID) * @return int */ - public function findUserId(int $fd, $run_id = SERVER_RUN_ID) + public function findUserId(int $fd, $run_id = SERVER_RUN_ID): int { return (int)$this->get($run_id, strval($fd)) ?: 0; } diff --git a/app/Cache/SocketRoom.php b/app/Cache/SocketRoom.php index 0768201..1377adc 100644 --- a/app/Cache/SocketRoom.php +++ b/app/Cache/SocketRoom.php @@ -4,6 +4,11 @@ namespace App\Cache; use App\Cache\Repository\SetGroupRedis; +/** + * 聊天室 - 缓存助手 + * + * @package App\Cache + */ class SocketRoom extends SetGroupRedis { protected $name = 'ws:room'; diff --git a/app/Cache/SocketUserBindFds.php b/app/Cache/SocketUserBindFds.php index a3eb12c..bb04604 100644 --- a/app/Cache/SocketUserBindFds.php +++ b/app/Cache/SocketUserBindFds.php @@ -71,7 +71,7 @@ class SocketUserBindFds extends SetGroupRedis * @param string $run_id 服务运行ID(默认当前服务ID) * @return array */ - public function findFds(int $user_id, $run_id = SERVER_RUN_ID) + public function findFds(int $user_id, $run_id = SERVER_RUN_ID): array { $arr = $this->all($this->filter([$run_id, $user_id])); foreach ($arr as $k => $value) { @@ -81,7 +81,7 @@ class SocketUserBindFds extends SetGroupRedis return $arr; } - public function getCachePrefix(string $run_id) + public function getCachePrefix(string $run_id): string { return $this->getCacheKey($run_id); } diff --git a/app/Cache/UnreadTalk.php b/app/Cache/UnreadTalk.php index bb4d19f..f96dd88 100644 --- a/app/Cache/UnreadTalk.php +++ b/app/Cache/UnreadTalk.php @@ -31,7 +31,7 @@ class UnreadTalk extends HashRedis * @param int $receive 接收者ID * @return int */ - public function read(int $sender, int $receive) + public function read(int $sender, int $receive): int { return (int)$this->get($this->flag($sender, $receive)); } @@ -63,7 +63,7 @@ class UnreadTalk extends HashRedis * @param int $user_id 用户ID * @return array */ - public function reads(int $user_id) + public function reads(int $user_id): array { $iterator = null; $arr = []; diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index 576ef33..c6fb756 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -68,12 +68,14 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos */ public function onOpen($server, Request $request): void { - $token = $request->get['token'] ?? ''; - $userInfo = $this->jwt->getParserData($token); + $token = $request->get['token'] ?? ''; + $userInfo = $this->jwt->getParserData($token); + $userInfo['user_id'] = intval($userInfo['user_id']); + stdout_log()->notice("用户连接信息 : user_id:{$userInfo['user_id']} | fd:{$request->fd} 时间:" . date('Y-m-d H:i:s')); // 判断是否存在异地登录 - $isOnline = $this->socketClientService->isOnlineAll(intval($userInfo['user_id'])); + $isOnline = $this->socketClientService->isOnlineAll($userInfo['user_id']); // 若开启单点登录,则主动关闭之前登录的连接 if ($isOnline) { @@ -129,7 +131,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos */ public function onClose($server, int $fd, int $reactorId): void { - $user_id = (int)$this->socketClientService->findFdUserId($fd); + $user_id = $this->socketClientService->findFdUserId($fd); stdout_log()->notice("客户端FD:{$fd} 已关闭连接 ,用户ID为【{$user_id}】,关闭时间:" . date('Y-m-d H:i:s')); diff --git a/app/Service/SocketClientService.php b/app/Service/SocketClientService.php index b15d099..6fb1c8b 100644 --- a/app/Service/SocketClientService.php +++ b/app/Service/SocketClientService.php @@ -58,7 +58,7 @@ class SocketClientService * @param array $run_ids 服务运行ID * @return bool */ - public function isOnlineAll(int $user_id, array $run_ids = []) + public function isOnlineAll(int $user_id, array $run_ids = []): bool { return SocketUserBindFds::getInstance()->isOnlineAll($user_id, $run_ids); } @@ -70,7 +70,7 @@ class SocketClientService * @param string $run_id 服务运行ID(默认当前服务ID) * @return int */ - public function findFdUserId(int $fd, $run_id = SERVER_RUN_ID) + public function findFdUserId(int $fd, $run_id = SERVER_RUN_ID): int { return SocketFdBindUser::getInstance()->findUserId($fd, $run_id); }