Explorar o código

gateway过滤不解密的接口
接收广电激活成功的数据接口

mac %!s(int64=2) %!d(string=hai) anos
pai
achega
d6d80ad638

+ 12 - 0
kxs-gateway/src/main/java/com/kxs/gateway/api/config/GatewayConfigProperties.java

@@ -19,6 +19,7 @@ import java.util.List;
 public class GatewayConfigProperties {
 
 	private AesConfigProperties aes = new AesConfigProperties();
+	private RequestProperties request = new RequestProperties();
 
 	@Data
 	public static class AesConfigProperties {
@@ -36,6 +37,17 @@ public class GatewayConfigProperties {
 
 	}
 
+	@Data
+	public class RequestProperties {
+
+		/**
+		 * 需要过滤不解密的接口
+		 */
+		private List<String> filterUrl;
+
+
+	}
+
 	/**
 	 * 网关不需要校验验证码的客户端 {@link com.kxs.gateway.api.filter.ValidateCodeGatewayFilter}
 	 */

+ 3 - 3
kxs-gateway/src/main/java/com/kxs/gateway/api/config/GatewayConfiguration.java

@@ -19,7 +19,7 @@ import org.springframework.data.redis.core.RedisTemplate;
  * @date 2023-11-11
  */
 @Configuration(proxyBeanMethods = false)
-@EnableConfigurationProperties(GatewayConfigProperties.class)
+@EnableConfigurationProperties({GatewayConfigProperties.class})
 public class GatewayConfiguration {
 
 	@Bean
@@ -28,8 +28,8 @@ public class GatewayConfiguration {
 	}
 
 	@Bean
-	public RequestDecoderFilter requestDecoderFilter(AES cryptoAes) {
-		return new RequestDecoderFilter(cryptoAes);
+	public RequestDecoderFilter requestDecoderFilter(AES cryptoAes, GatewayConfigProperties configProperties) {
+		return new RequestDecoderFilter(cryptoAes, configProperties);
 	}
 
 	@Bean

+ 3 - 2
kxs-gateway/src/main/java/com/kxs/gateway/api/config/ResponseProperties.java

@@ -5,11 +5,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 
 import java.util.List;
 
+
 /**
  * 过滤接口后转发到老系统
  *
- * @author : liukx
- * @time : 2020/9/22 - 17:03
+ * @author 没秃顶的码农
+ * @date 2024-06-18
  */
 @Data
 @ConfigurationProperties(prefix = "gateway.dts.response")

+ 10 - 0
kxs-gateway/src/main/java/com/kxs/gateway/api/filter/RequestDecoderFilter.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.kxs.common.core.constant.enums.ErrorTypeEnum;
 import com.kxs.common.core.exception.AesDecodeException;
+import com.kxs.gateway.api.config.GatewayConfigProperties;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.jetbrains.annotations.NotNull;
@@ -51,6 +52,9 @@ public class RequestDecoderFilter extends AbstractGatewayFilterFactory<Object> {
 
     private final AES cryptoAes;
 
+    private final GatewayConfigProperties requestProperties;
+
+
     private static final String PARAM_NAME = "value";
 
     /**
@@ -68,6 +72,12 @@ public class RequestDecoderFilter extends AbstractGatewayFilterFactory<Object> {
 
             MediaType contentType = request.getHeaders().getContentType();
 
+            List<String> filterUrl = requestProperties.getRequest().getFilterUrl();
+            String path = request.getURI().getPath();
+            //过滤接口不解密
+            if (!filterUrl.isEmpty() && filterUrl.contains(path)) {
+                return chain.filter(exchange);
+            }
             if (contentType != null && FILE_TYPES.stream().anyMatch(contentType.toString()::startsWith)) {
                 // 这是一个文件请求
                 return chain.filter(exchange);

+ 12 - 5
kxs-gateway/src/main/java/com/kxs/gateway/api/filter/ResponseFilter.java

@@ -106,8 +106,11 @@ public class ResponseFilter implements GlobalFilter, Ordered {
                             if (Objects.equals(status, CommonConstants.SUCCESS)) {
                                 //获取请求token
                                 List<String> tokens = exchange.getRequest().getHeaders().get(HttpHeaders.AUTHORIZATION);
-                                assert tokens != null;
-                                sendMsg(path, exchange.getAttribute("requestBody"), tokens.get(0));
+                                if(tokens != null){
+                                    sendMsg(path, exchange.getAttribute("requestBody"), tokens.get(0));
+                                }else{
+                                    sendMsg(path, exchange.getAttribute("requestBody"), null);
+                                }
 
                             }
 
@@ -143,10 +146,14 @@ public class ResponseFilter implements GlobalFilter, Ordered {
     }
 
     private void sendMsg(String url, String param, String token) {
-        if (token.startsWith("Bearer ")) {
-            token = token.substring(7);
+        Object userId = null;
+        if(StrUtil.isNotBlank(token)){
+            if (token.startsWith("Bearer ")) {
+                token = token.substring(7);
+            }
+            userId = redisTemplate.opsForValue().get(token);
         }
-        Object userId = redisTemplate.opsForValue().get(token);
+
 
         //发送消息
         RabbitDtsMethodQueueMQ msg = RabbitDtsMethodQueueMQ.build(RabbitDtsMethodQueueMQ.MsgEntity.builder()

+ 3 - 3
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/service/KxsGdService.java

@@ -1,6 +1,6 @@
 package com.kxs.product.biz.service;
 
-import com.alibaba.fastjson.JSONObject;
+import java.util.Map;
 
 /**
  * KXS 广电 服务
@@ -23,7 +23,7 @@ public interface KxsGdService {
     /**
      * 匹配 广电 开卡数据 接收推送
      *
-     * @param orderData 订单数据
+     * @param param 订单数据
      */
-    void checkGdAsyncData(JSONObject orderData);
+    void checkGdAsyncData(Map<String, Object> param);
 }

+ 2 - 9
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/service/impl/KxsGdReportServiceImpl.java

@@ -30,6 +30,7 @@ import com.kxs.product.biz.constant.enums.GdReportEnum;
 import com.kxs.product.biz.mapper.KxsGdReportMapper;
 import com.kxs.product.biz.service.KxsGdReportService;
 import com.kxs.product.biz.service.KxsGdService;
+import com.kxs.product.biz.util.GdRsaUtils;
 import com.kxs.user.api.feign.RemoteKxsUserService;
 import com.kxs.user.api.model.KxsUser;
 import lombok.RequiredArgsConstructor;
@@ -233,15 +234,7 @@ public class KxsGdReportServiceImpl extends ServiceImpl<KxsGdReportMapper, KxsGd
     @Override
     public void acceptActData(Map<String, Object> param) {
 
-        JSONArray dataList = JSON.parseArray(param.get("data").toString());
-        if(dataList.isEmpty()){
-            log.error("接收广电订单数据失败:{}", JSON.toJSONString(param));
-            return;
-        }
-        for (Object obj : dataList) {
-            JSONObject orderData = JSON.parseObject(obj.toString());
-            kxsGdService.checkGdAsyncData(orderData);
-        }
+        kxsGdService.checkGdAsyncData(param);
 
     }
 

+ 39 - 18
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/service/impl/KxsGdServiceImpl.java

@@ -7,6 +7,8 @@ import cn.hutool.core.lang.TypeReference;
 import cn.hutool.http.Header;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.kxs.common.core.exception.GlobalCustomerException;
@@ -28,6 +30,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 
 /**
@@ -87,30 +90,47 @@ public class KxsGdServiceImpl implements KxsGdService {
     }
 
     @Override
-    public void checkGdAsyncData(JSONObject orderData) {
+    public void checkGdAsyncData(Map<String, Object> param) {
 
-        String gdMobile = orderData.getString("mobile");
-        KxsGdReport kxsGdReport = kxsGdReportMapper.selectOne(Wrappers.<KxsGdReport>lambdaQuery()
-                .eq(KxsGdReport::getIsCheck, GdReportEnum.CHECK_NO.getType())
-                .eq(KxsGdReport::getGdMobile, gdMobile));
-        if (kxsGdReport == null) {
+        JSONArray dataList = JSON.parseArray(param.get("data").toString());
+        if(dataList.isEmpty()){
+            log.error("接收广电订单数据失败:{}", JSON.toJSONString(param));
             return;
         }
+        try {
+            boolean checkSign = GdRsaUtils.checkSign(param, rsaProperties.getGd().getPublicKey());
+            if(!checkSign) {
+                throw new GlobalCustomerException("广电接收激活数据验证签名失败");
+            }
+        } catch (Exception e) {
+            throw new GlobalCustomerException("广电接收激活数据验证签名失败");
+        }
+        for (Object obj : dataList) {
+            JSONObject orderData = JSON.parseObject(obj.toString());
+
+            String gdMobile = orderData.getString("mobile");
+            KxsGdReport kxsGdReport = kxsGdReportMapper.selectOne(Wrappers.<KxsGdReport>lambdaQuery()
+                    .eq(KxsGdReport::getIsCheck, GdReportEnum.CHECK_NO.getType())
+                    .eq(KxsGdReport::getGdMobile, gdMobile));
+            if (kxsGdReport == null) {
+                return;
+            }
 
-        RabbitGdActQueueMQ.MsgEntity msgEntity = new RabbitGdActQueueMQ.MsgEntity();
-        msgEntity.setPosSn(orderData.getString("iccid"));
-        msgEntity.setPhoneNo(orderData.getString("mobile"));
-        msgEntity.setProductName(orderData.getString("offerName"));
-        msgEntity.setActivationStatusName("已激活");
-        msgEntity.setActivationTime(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN));
+            RabbitGdActQueueMQ.MsgEntity msgEntity = new RabbitGdActQueueMQ.MsgEntity();
+            msgEntity.setPosSn(orderData.getString("iccid"));
+            msgEntity.setPhoneNo(orderData.getString("mobile"));
+            msgEntity.setProductName(orderData.getString("offerName"));
+            msgEntity.setActivationStatusName("已激活");
+            msgEntity.setActivationTime(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN));
 
-        mqSender.send(RabbitGdActQueueMQ.build(msgEntity));
+            mqSender.send(RabbitGdActQueueMQ.build(msgEntity));
 
-        kxsGdReportMapper.update(null, Wrappers.<KxsGdReport>lambdaUpdate().eq(KxsGdReport::getId, kxsGdReport.getId())
-                .set(KxsGdReport::getIsCheck, GdReportEnum.CHECK_SUC.getType())
-                .set(KxsGdReport::getGdMobile, gdMobile));
-        log.info("发送电渠广电激活数据{}", kxsGdReport.getGdSn()
-                + "," + kxsGdReport.getGdMobile());
+            kxsGdReportMapper.update(null, Wrappers.<KxsGdReport>lambdaUpdate().eq(KxsGdReport::getId, kxsGdReport.getId())
+                    .set(KxsGdReport::getIsCheck, GdReportEnum.CHECK_SUC.getType())
+                    .set(KxsGdReport::getGdMobile, gdMobile));
+            log.info("发送电渠广电激活数据{}", kxsGdReport.getGdSn()
+                    + "," + kxsGdReport.getGdMobile());
+        }
     }
 
 
@@ -130,6 +150,7 @@ public class KxsGdServiceImpl implements KxsGdService {
                     .timestamp(String.valueOf(timestamp)).build();
             String sign = GdRsaUtils.rsa256Sign(BeanUtil.beanToMap(req), rsaProperties.getGd().getPrivateKey());
             req.setSign(sign);
+            boolean b = GdRsaUtils.checkSign(BeanUtil.beanToMap(req), rsaProperties.getGd().getPublicKey());
             String body = JSONUtil.toJsonStr(req);
             String response = HttpRequest.post(url)
                     .header(Header.CONTENT_TYPE, "application/json")

+ 3 - 2
kxs-product/kxs-product-biz/src/main/java/com/kxs/product/biz/util/GdRsaUtils.java

@@ -33,8 +33,8 @@ public class GdRsaUtils {
 
     public static final String KEY_ALGORITHM = "RSA";
     public static final String DEFAULT_CHARSET = "UTF-8";
-    public static final String DEFAULT_PRIVATE_KEY = "";
-    public static final String DEFAULT_PUBLIC_KEY = "";
+    public static final String DEFAULT_PRIVATE_KEY = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJBIQq3hyV0EseFd6X+nzRc++bZoljQqqou2NPUW5RD+wLBTk08LGwhGq7hR9WlG95aQ3NHbqNT/Tt8eiH9a8k7FzXHDzGAnGpYTh1fCzSx+lzmRA0E8WUH2CdjSLiNxb4Dxvqcrht5TpgFp2NRaGIIAvB+h8QZ1Uhjux5LGiJaJAgMBAAECgYBl65WmrSOIYOOi9qsWMRvwetz9HL5WFXmp/clFBKpFqh/FrxQVNxweaYWuS78XYjlNlAFZAVkvNTaq6C+1/zHAl3YmRowVz2ut1WoTT5MjZBJsR1d7SnSKp/ZuquKGGPG9l1jbUgY6CfekUhvKzUdk3/k7r3zUzUzEWq4dDdM/XQJBAP2SwEDg78nJxKMBmjKYwEpYYYL6DxTYje9J07/Ms7L8W7OtIj+Xm6I0siBWLe4Y5tVtBzaohxnbzoKfNODaNFMCQQCRqb+5fD02I+Sa62gTQepb1u1HgguS1KfFB0inmwMs+VEFYs73N8LC3PSzONhOLlIV/bzs4CvpnMHyF16qie4zAkEA9GBR2DTv41EIqPAKY2jDKOM0Vr4XeseZQlusLtRg+sYqumbI8vBxlUmjwXZMnYJyNI32vb59NXaY91nn5Ctm8QJAYSwkwtCm5R88ujygyXgHqAzRbgrLPcCvyzj4txcqHy6TZkxsVW/VdbmBZK5fXoh4KkODbWJ+6PGyUJZWiN5LEQJAelIs1KLSVQ+GAzDslXIyxYhTP9yLcxAMbCuQ3tY0jbsyYyB/WuxTvIdwGfGp/GLht36/6RqsRc9JtAyMeXkE1g==";
+    public static final String DEFAULT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZ+zsPxpoM85OFlHOqN3aauub5PqC8lmfFQKgWz7XITCPsWdYrBY/Niu29tSNchYZq+wrboyhrhCx9PacWeF5hQ0qkOIw/vcLQJe4RWXj3eBMfbqj7a2dJlcFI12TP0m1lCaI5z9lZ1FHtZDzU0lBBiRUCRNsJa/ktrt1MjU7nAQIDAQAB";
 
     /**
      * 获取公钥
@@ -276,6 +276,7 @@ public class GdRsaUtils {
         // 验签
         reqParams.put("sign", sign);
         final boolean result = GdRsaUtils.checkSign(reqParams, DEFAULT_PUBLIC_KEY);
+        System.out.println("验证签名:" + result);
         assert result;
     }