fix:即时通知通过STOMP下发
This commit is contained in:
@@ -59,7 +59,8 @@ public class SignValidateFilter implements Filter {
|
||||
"/zxjp/mini/program/v1/partnerManage/openArea/areaApplyQuery",
|
||||
"/zxjp/**/api/audit/result",
|
||||
"/zxjp/**/api/license",
|
||||
"/zxjp/mini/line/getRegionPayPic"
|
||||
"/zxjp/mini/line/getRegionPayPic",
|
||||
"/zxjp/ws/**"
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ public class TokenValidateFilter implements Filter {
|
||||
"/zxjp/pc/video/**",
|
||||
"/zxjp/**/api/license",
|
||||
"/zxjp/pc/v3/login/accountLogin",
|
||||
"/zxjp/pc/v3/login/refreshLogin"
|
||||
"/zxjp/pc/v3/login/refreshLogin",
|
||||
"/zxjp/ws/**"
|
||||
|
||||
|
||||
);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.cool.store.config.websocket;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.simp.config.ChannelRegistration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* WebSocket配置类
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/2
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSocketMessageBroker
|
||||
@Slf4j
|
||||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
|
||||
|
||||
@Override
|
||||
public void registerStompEndpoints(StompEndpointRegistry registry) {
|
||||
registry.addEndpoint("/ws/zxzs")
|
||||
.setAllowedOrigins("*")
|
||||
.withSockJS(); // 启用SockJS支持
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageBroker(MessageBrokerRegistry registry) {
|
||||
// 配置消息代理
|
||||
registry.enableSimpleBroker("/topic", "/queue"); // 启用简单代理,用于广播和点对点消息
|
||||
registry.setApplicationDestinationPrefixes("/app"); // 设置应用程序端点前缀
|
||||
// registry.setUserDestinationPrefix("/user");
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void configureClientInboundChannel(ChannelRegistration registration) {
|
||||
// registration.interceptors(new ChannelInterceptor() {
|
||||
// @Override
|
||||
// public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
// StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
|
||||
//
|
||||
// if (StompCommand.CONNECT.equals(accessor.getCommand())) {
|
||||
// // 从STOMP头部获取login字段作为用户标识
|
||||
// String login = accessor.getLogin();
|
||||
// log.info("用户login:{}", login);
|
||||
// if (login != null && !login.isEmpty()) {
|
||||
// // 设置用户身份
|
||||
// accessor.setUser(() -> login);
|
||||
// }
|
||||
// }
|
||||
// return message;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.login.LoginBaseService;
|
||||
import com.cool.store.service.login.LoginStrategy;
|
||||
import com.cool.store.utils.SpringContextUtil;
|
||||
import com.cool.store.vo.login.UserLoginVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -28,13 +29,13 @@ public class LoginController {
|
||||
|
||||
@ApiOperation("账号密码登录")
|
||||
@PostMapping("/accountLogin")
|
||||
public ResponseResult accountLogin(@RequestBody UserLoginDTO param) {
|
||||
public ResponseResult<UserLoginVO> accountLogin(@RequestBody UserLoginDTO param) {
|
||||
return SpringContextUtil.getBean(param.getLoginType().getClazzName(), LoginStrategy.class).login(param);
|
||||
}
|
||||
|
||||
@ApiOperation("refresh登录")
|
||||
@PostMapping("/refreshLogin")
|
||||
public ResponseResult refreshLogin(@RequestBody UserRefreshLoginDTO param) {
|
||||
public ResponseResult<UserLoginVO> refreshLogin(@RequestBody UserRefreshLoginDTO param) {
|
||||
return loginBaseService.refreshLogin(param);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user