From 74e6d5a1dae956905996b4ae17f0d837e0e0749c Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 11 Nov 2024 17:24:49 +0800 Subject: [PATCH] =?UTF-8?q?ws=20=E8=81=94=E8=B0=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/common/websocket/NotificationConnection.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ai/da/common/websocket/NotificationConnection.java b/src/main/java/com/ai/da/common/websocket/NotificationConnection.java index 55bd53ad..595f268a 100644 --- a/src/main/java/com/ai/da/common/websocket/NotificationConnection.java +++ b/src/main/java/com/ai/da/common/websocket/NotificationConnection.java @@ -1,7 +1,10 @@ package com.ai.da.common.websocket; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; import javax.websocket.*; import javax.websocket.server.PathParam; @@ -55,11 +58,12 @@ public class NotificationConnection { //收到了客户端消息执行的操作 @OnMessage - public void onMessage(String text){ - log.info("收到了一条来自 {} 的消息:{}", this.userId, text); + public void onMessage(@RequestParam String text){ + Map textMap = JSONObject.parseObject(text, Map.class); + log.info("收到了一条来自 {} 的消息:{}, sessionId:{}", this.userId, textMap.get("text"), this.session.getId()); // return "已收到你的消息"; - if (text.equals("PING")){ - sendMsg("PONG", this.userId); + if (textMap.get("text").equals("PING")){ + sendMsg(JSON.toJSONString("PONG"), this.userId); } }