listen('clientLogin', [$this,'onClientLogin']); $event->listen('lockClient',[$this,'onLockClient']); $event->listen('clientClose',[$this,'onClientClose']); } /** * Ws客户端登录 * @param PutMessage $put * @param SysUser $sysUser * @return void * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function onClientLogin($data): void { var_dump($data); var_dump("事件触发 "); return; $client = SysUserClient::where([ 'client_id' => $put->getClientId(), 'client_name'=> $put->getClientName(), 'user_id' => $put->userId, ])->find(); /* * 判断客户端是否锁定状态 */ if($client && $client['is_lock']) { // 通知客户端锁定屏幕 GatewayClientService::sendToClient($put->wsClientId,new OutMessage( WsTypeEnum::System, WsEventEnum::Lock_Client, )); } /* * 客户端登录通知 */ $ip = $_SERVER['REMOTE_ADDR'] ?? ''; GatewayClientService::sendToClient($put->wsClientId, new OutMessage( WsTypeEnum::System, WsEventEnum::Notification, new ElNotification(title: '登录成功,欢迎您', message: "当前登录Ip: $ip"), )); } /** * Ws客户端锁定 * @param PutMessage $put * @return void * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function onLockClient(PutMessage $put): void { $client = SysUserClient::where([ 'client_id' => $put->getClientId(), 'client_name'=> $put->getClientName(), 'user_id' => $put->userId, ])->find(); if($client) { // 加密传递的锁屏密码 $lock_password = password_hash($put->get('password',''), PASSWORD_DEFAULT); // 保存锁屏信息 $client->save([ 'is_lock'=>1, 'lock_password'=>$lock_password, 'lock_time'=>date('Y-m-d H:i:s') ]); // 保存锁屏日志 SysUserClientLog::create([ 'event' => "{$put->type->value}.{$put->event->value}", 'message'=> "A. 锁定客户端", 'data' => json_encode(['inputPass'=> $lock_password]), 'create_time' => date('Y-m-d H:i:s'), 'client_data_id' => $client['id'] ]); // 通知客户端锁定屏幕 GatewayClientService::sendToClient($put->wsClientId,new OutMessage( WsTypeEnum::System, WsEventEnum::Lock_Client, )); } } /** * Ws客户端连接被关闭 * @return void */ public function onClientClose() { } }