withAuthority($authorization);方法将认证后的用户与链接进行关联 * * @param ConstrictRequest $request * @return bool */ public function onConnected(RequestInterface $request): bool { // TODO: Implement onConnected() method. // $request->withAuthority(null); return false; } /** * * 客户端发送的消息回调 * * @param ConstrictRequest $psr7Request * @param string $frame * @return void */ public function onMessage(RequestInterface $psr7Request, string $frame): void { // TODO: Implement onMessage() method. } /** * 消息循环之前调用的函数(此时链接已加入管理中) * @return void * */ public function onBeforeMessageLoop(): void { // TODO: Implement onBeforeMessageLoop() method. } /** * @param int $userId * @return void */ public function onDisconnect(int $userId): void { // TODO: Implement onDisconnect() method. } /** * @return void */ public function onStart(): void { } } run(function () { $config = new Config; $config->port = 9501; $config->host = '0.0.0.0'; $config->authKey = 'access_token'; $websocket = Kiri::getDi()->get(Test::class); $websocket->start($config); });