From a2d5cb2d6e74d483468cfeb3ec6c6b133348b23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E7=A3=8A?= <45566618@qq.com> Date: Fri, 30 Aug 2024 11:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E5=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sqx/modules/chat/controller/app/AppChatSocket.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sqx/modules/chat/controller/app/AppChatSocket.java b/src/main/java/com/sqx/modules/chat/controller/app/AppChatSocket.java index 45b47e4..de88980 100644 --- a/src/main/java/com/sqx/modules/chat/controller/app/AppChatSocket.java +++ b/src/main/java/com/sqx/modules/chat/controller/app/AppChatSocket.java @@ -35,8 +35,6 @@ public class AppChatSocket {//用户聊天 */ private static Map clients = new ConcurrentHashMap(); - private static Map sessionMap = new ConcurrentHashMap(); - private static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /** * 会话 @@ -80,7 +78,6 @@ public class AppChatSocket {//用户聊天 clients.remove(userId); } clients.put(userId, this); - sessionMap.put(userId,session); /*sendMessageTo("恭喜你连接成功!",wxUserId);*/ } @@ -143,9 +140,9 @@ public class AppChatSocket {//用户聊天 // } List toUsers = chatContentService.selectUserByConversationId(Long.parseLong(chatConversationId)); for(ChatContent toUser :toUsers){ - Session userSession = sessionMap.get(toUser.getUserId()); - if (userSession!=null) { - userSession.getAsyncRemote().sendText(message); + AppChatSocket chatSocket = clients.get(toUser.getUserId()); + if (chatSocket!=null) { + chatSocket.session.getAsyncRemote().sendText(message); System.err.println(this.userId+"发送成功:"+userId); } }