From 4ae4c1918621e2e3ceedb1f556c377e6d13cabb9 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Sun, 11 Jul 2021 22:10:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Event/UserLogin.php | 23 +++++++++++++++++++- app/Listener/UserLoginListener.php | 2 +- change.sql | 34 ------------------------------ 3 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 change.sql diff --git a/app/Event/UserLogin.php b/app/Event/UserLogin.php index 4fc6057..1cd8648 100644 --- a/app/Event/UserLogin.php +++ b/app/Event/UserLogin.php @@ -38,6 +38,27 @@ class UserLogin $this->platform = $request->input('platform', ''); - $this->ip = $request->getServerParams()['remote_addr']; + $this->ip = $this->getClientRealIp($request); + } + + /** + * 获取用户真实 IP + * + * @param RequestInterface $request + * @return mixed + */ + private function getClientRealIp(RequestInterface $request) + { + $params = $request->getServerParams(); + + $real_ip = $params["remote_addr"]; + + if (isset($params["http_x_forwarded_for"])) { + $real_ip = $params["http_x_forwarded_for"]; + } else if (isset($params["HTTP_CLIENT_IP"])) { + $real_ip = $params["http_client_ip"]; + } + + return $real_ip; } } diff --git a/app/Listener/UserLoginListener.php b/app/Listener/UserLoginListener.php index 28bd1c6..15d46c7 100644 --- a/app/Listener/UserLoginListener.php +++ b/app/Listener/UserLoginListener.php @@ -24,7 +24,7 @@ class UserLoginListener implements ListenerInterface */ public function process(object $event) { - // echo $event->user->id . ':' . $event->platform . ':' . $event->ip; // 推送登录提示信息 + stdout_log()->notice('登录事件回调 ' . $event->user->mobile . ':' . $event->platform . ':' . $event->ip); } } diff --git a/change.sql b/change.sql deleted file mode 100644 index 7ab6766..0000000 --- a/change.sql +++ /dev/null @@ -1,34 +0,0 @@ -# lar_group -ALTER TABLE lar_users_group RENAME lar_group; -ALTER TABLE lar_group CHANGE `user_id` `creator_id` int(11) unsigned DEFAULT '0' COMMENT '创建者ID(群主ID)'; -ALTER TABLE lar_group CHANGE `status` `is_dismiss` tinyint(4) unsigned DEFAULT '0' COMMENT '是否已解散[0:否;1:是;]'; -ALTER TABLE lar_group CHANGE `group_profile` `profile` varchar(100) DEFAULT '' COMMENT '群介绍'; -ALTER TABLE lar_group ADD `max_num` smallint(5) unsigned DEFAULT '200' COMMENT '最大群成员数量'; -ALTER TABLE lar_group ADD `is_overt` tinyint(4) unsigned DEFAULT '0' COMMENT '是否公开可见[0:否;1:是;]'; -ALTER TABLE lar_group ADD `is_mute` tinyint(4) unsigned DEFAULT '0' COMMENT '是否全员禁言 [0:否;1:是;],提示:不包含群主或管理员'; -ALTER TABLE lar_group ADD `dismissed_at` datetime DEFAULT NULL COMMENT '解散时间'; - -# ------------------ - -# lar_group_member -ALTER TABLE lar_users_group_member RENAME lar_group_member; -ALTER TABLE lar_group_member MODIFY `group_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '群组ID'; -ALTER TABLE lar_group_member MODIFY `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID'; -ALTER TABLE lar_group_member CHANGE `group_owner` `leader` tinyint(4) unsigned DEFAULT '0' COMMENT '成员属性[0:普通成员;1:管理员;2:群主;]'; -ALTER TABLE lar_group_member CHANGE `status` `is_quit` tinyint(4) DEFAULT '0' COMMENT '是否退群[0:否;1:是;]'; -ALTER TABLE lar_group_member CHANGE `visit_card` `user_card` varchar(20) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '群名片'; -ALTER TABLE lar_group_member ADD `is_mute` tinyint(4) unsigned DEFAULT '0' COMMENT '是否禁言[0:否;1:是;]'; -ALTER TABLE lar_group_member ADD `deleted_at` datetime DEFAULT NULL COMMENT '退群时间'; -update lar_group_member set leader = 2 where leader = 1; - -# ------------------ - -# lar_group_notice -ALTER TABLE lar_users_group_notice RENAME lar_group_notice; -ALTER TABLE lar_group_notice MODIFY `group_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '群组ID'; -ALTER TABLE lar_group_notice CHANGE `user_id` `creator_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建者用户ID'; -ALTER TABLE lar_group_notice MODIFY `title` varchar(50) CHARACTER SET utf8mb4 DEFAULT '' COMMENT '公告标题'; -ALTER TABLE lar_group_notice ADD `is_top` tinyint(4) unsigned DEFAULT '0' COMMENT '是否置顶[0:否;1:是;]'; -ALTER TABLE lar_group_notice MODIFY `is_delete` tinyint(4) unsigned DEFAULT '0' COMMENT '是否删除[0:否;1:是;]'; -ALTER TABLE lar_group_notice ADD `is_confirm` tinyint(4) DEFAULT '0' COMMENT '是否需群成员确认公告[0:否;1:是;]'; -ALTER TABLE lar_group_notice ADD `confirm_users` json DEFAULT NULL COMMENT '已确认成员';