ws 联调修改

This commit is contained in:
2024-11-11 17:24:49 +08:00
parent 3cf0570912
commit 74e6d5a1da

View File

@@ -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<String, String> 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);
}
}