1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Component public class AllbsAuthHandler extends AuthMessageHandler {
@Override public void execute(WebSocketSession session, AuthRequest message) { if (!StrUtil.isAllNotEmpty(message.getAccessToken(), message.getUserName())) { WebSocketUtil.send(session, "401", AuthResponse.builder().content(StrUtil.format("参数{}为必传参数", "userName")).build()); throw new MessageHandlerException("缺少必要参数userName!"); } WebSocketUtil.addSession(session, message.getUserName()); WebSocketUtil.send(session, "200", AuthResponse.builder().content("连接成功").build()); } }
|