Explorar o código

feat(system): 添加公司简介字段并实现WebSocket认证处理器- 在BasicInfo实体类中新增companyProfileTwo字段用于存储公司简介
- 更新BasicInfoMapper.xml配置文件,添加companyProfileTwo字段映射
- 实现AuthHandshakeHandler WebSocket握手认证处理器,支持token验证- 集成RedisTemplate进行token有效性检查
- 添加URL参数解析逻辑,从请求中提取token进行身份验证
- 实现认证失败时自动关闭连接机制- 为非HTTP请求消息提供直接传递通道

nahida hai 7 meses
pai
achega
9a89f6023d

+ 6 - 0
zksy-system/src/main/java/com/zksy/base/domain/BasicInfo.java

@@ -30,6 +30,12 @@ public class BasicInfo implements Serializable {
     @TableField(value = "company_profile")
     @TableField(value = "company_profile")
     private String companyProfile;
     private String companyProfile;
 
 
+    /**
+     * 公司简介
+     */
+    @TableField(value = "company_profile_two")
+    private String companyProfileTwo;
+
     /**
     /**
      * 公司简介图片地址
      * 公司简介图片地址
      */
      */

+ 2 - 1
zksy-system/src/main/resources/mapper/base/BasicInfoMapper.xml

@@ -7,6 +7,7 @@
     <resultMap id="BaseResultMap" type="com.zksy.base.domain.BasicInfo">
     <resultMap id="BaseResultMap" type="com.zksy.base.domain.BasicInfo">
             <id property="id" column="id" jdbcType="VARCHAR"/>
             <id property="id" column="id" jdbcType="VARCHAR"/>
             <result property="companyProfile" column="company_profile" jdbcType="VARCHAR"/>
             <result property="companyProfile" column="company_profile" jdbcType="VARCHAR"/>
+            <result property="companyProfileTwo" column="company_profile_two" jdbcType="VARCHAR"/>
             <result property="companyProfileUrl" column="company_profile_url" jdbcType="VARCHAR"/>
             <result property="companyProfileUrl" column="company_profile_url" jdbcType="VARCHAR"/>
             <result property="softwareIntroduction" column="software_introduction" jdbcType="VARCHAR"/>
             <result property="softwareIntroduction" column="software_introduction" jdbcType="VARCHAR"/>
             <result property="hardwareIntroduction" column="hardware_introduction" jdbcType="VARCHAR"/>
             <result property="hardwareIntroduction" column="hardware_introduction" jdbcType="VARCHAR"/>
@@ -23,7 +24,7 @@
     </resultMap>
     </resultMap>
 
 
     <sql id="Base_Column_List">
     <sql id="Base_Column_List">
-        id,company_profile,company_profile_url,
+        id,company_profile,company_profile_two,company_profile_url,
         software_introduction,hardware_introduction,telephone,
         software_introduction,hardware_introduction,telephone,
         service_hotline,consultation_hotline,email,
         service_hotline,consultation_hotline,email,
         address,qr_code_url,create_by,
         address,qr_code_url,create_by,

+ 49 - 0
zksy-ws/src/main/java/com/zksy/server/AuthHandshakeHandler.java

@@ -0,0 +1,49 @@
+package com.zksy.server;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.QueryStringDecoder;
+import lombok.RequiredArgsConstructor;
+import org.springframework.data.redis.core.RedisTemplate;
+
+@RequiredArgsConstructor
+public class AuthHandshakeHandler extends ChannelInboundHandlerAdapter {
+
+    private final RedisTemplate<Object, Object> redisTemplate;
+
+    
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        if (msg instanceof FullHttpRequest) {
+            FullHttpRequest request = (FullHttpRequest) msg;
+
+            // 方法1: 从URL参数中获取token进行验证
+            QueryStringDecoder decoder = new QueryStringDecoder(request.uri());
+            String token = decoder.parameters().get("token") != null ?
+                          decoder.parameters().get("token").get(0) : null;
+            if (isValidToken(token)) {
+                // 验证通过,继续处理
+                super.channelRead(ctx, msg);
+            } else {
+                // 验证失败,关闭连接
+                ctx.close();
+            }
+        } else {
+            // 非HTTP请求消息,直接传递
+            super.channelRead(ctx, msg);
+        }
+    }
+    
+    /**
+     * 验证token的有效性
+     * @param token
+     * @return
+     */
+    private boolean isValidToken(String token) {
+        Object count = redisTemplate.opsForValue().get("ws:token:" + token);
+
+        return count != null && (Integer) count > 0;
+    }
+
+}