Compare commits
2 Commits
07da67bc80
...
2249f74b9a
Author | SHA1 | Date |
---|---|---|
zrh050423 | 2249f74b9a | |
zrh050423 | d520d06026 |
|
@ -18,4 +18,5 @@ public class HealthSystemApplication {
|
|||
SpringApplication.run(HealthSystemApplication.class, args);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||
|
||||
// 仅对非登录和注册请求进行过滤
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.contains("/login") || uri.contains("/register")) {
|
||||
if (uri.contains("/login") || uri.contains("/register")||uri.contains("/socket.io")||uri.contains("/ws")) {
|
||||
filterChain.doFilter(request, response);
|
||||
return; // 如果是登录或注册接口,直接通过,不做 token 验证
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package edu.zrh.healthsystem.config;
|
||||
|
||||
import com.corundumstudio.socketio.AckRequest;
|
||||
import com.corundumstudio.socketio.SocketIOClient;
|
||||
import com.corundumstudio.socketio.annotation.OnConnect;
|
||||
import com.corundumstudio.socketio.annotation.OnDisconnect;
|
||||
import com.corundumstudio.socketio.annotation.OnEvent;
|
||||
import edu.zrh.healthsystem.model.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MessageEventHandler {
|
||||
|
||||
@OnConnect
|
||||
public void onConnect(SocketIOClient client) {
|
||||
// 客户端连接时调用
|
||||
}
|
||||
|
||||
@OnDisconnect
|
||||
public void onDisconnect(SocketIOClient client) {
|
||||
// 客户端断开连接时调用
|
||||
}
|
||||
|
||||
@OnEvent(value = "send")
|
||||
public void onSendMessage(SocketIOClient client, AckRequest request, Message message) {
|
||||
// 接收到客户端发送的消息时调用
|
||||
client.getNamespace().getBroadcastOperations().sendEvent("topic/message", message);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,10 @@ package edu.zrh.healthsystem.model;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author han
|
||||
*/
|
||||
public @Data class Message {
|
||||
private String role="user";
|
||||
private String content;
|
||||
private String from;
|
||||
private String text;
|
||||
}
|
Loading…
Reference in New Issue