Sfoglia il codice sorgente

推送加密的毕节机场闸机数据到毕节公安,使用sm4对称加密方式.

lsh 3 settimane fa
parent
commit
005297d239

+ 62 - 0
src/main/java/com/yx/face/model/dto/BiJieGADto.java

@@ -0,0 +1,62 @@
+package com.yx.face.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+ * @description: 推送给毕节公安的数据dto
+ * @date: 2024-12-11
+ */
+
+@ApiModel(" 推送给毕节公安的数据dto")
+@Data
+public class BiJieGADto {
+
+    /**
+     * 编号
+     */
+    private String Id;
+    /**
+     * "姓名",
+     */
+    private String Name;
+    /**
+     * "证件号码",
+     */
+    private String Zjhm;
+    /**
+     * "证件类型",
+     */
+    private String Zjlx;
+    /**
+     * "匣机名",
+     */
+    private String Zjmc;
+    /**
+     * "匣机地址",
+     */
+    private String Zjdz;
+    /**
+     * "行政区划代码",
+     */
+    private String Xzqh;
+    /**
+     * : "通过时间",
+     */
+    private String Tgtime;
+    /**
+     * "闸机编号",
+     */
+    private String Zjbh;
+    /**
+     * : "推送时间",
+     */
+    private String Tstime;
+    /**
+     * "base64图片
+     */
+    private String Image;
+
+
+}
+

+ 22 - 0
src/main/java/com/yx/face/service/PushToThirdPartyService.java

@@ -0,0 +1,22 @@
+package com.yx.face.service;
+
+import com.yx.face.model.entity.FaceLog;
+import com.yx.face.model.entity.FaceLogFrom;
+
+/**
+ *
+ * @description: 发送给第三方
+ * @date: 2024/12/11 >
+ * @author: LSH
+ */
+public interface PushToThirdPartyService {
+
+    /**
+     * @return java.lang.Boolean <br>
+     * @description: 下发人脸 <br>
+     * @date: 2021/6/3 14:44 <br>
+     * @author: PWB <br>
+     */
+    void sendToOther(Integer adminId, FaceLog faceLog, String photo);
+
+}

+ 6 - 0
src/main/java/com/yx/face/service/impl/FaceTBServiceImpl.java

@@ -20,6 +20,7 @@ import com.yx.face.model.dto.FacePassDTO;
 import com.yx.face.model.entity.*;
 import com.yx.face.model.vo.SystemLongTermDocumentsVO;
 import com.yx.face.service.FaceTBService;
+import com.yx.face.service.PushToThirdPartyService;
 import com.yx.face.service.UserControlEarlyWarningListService;
 import com.yx.face.service.feign.TBDeviceFaceService;
 import lombok.extern.slf4j.Slf4j;
@@ -77,6 +78,9 @@ public class FaceTBServiceImpl implements FaceTBService {
 
     @Value("${web.address}")
     private String address;
+
+    @Resource
+    private PushToThirdPartyService pushToThirdPartyService;
 //
 //    @Autowired
 //    private NettyClient nettyClient;
@@ -704,6 +708,8 @@ public class FaceTBServiceImpl implements FaceTBService {
                         //预警数据插入
                         userControlEarlyWarningListService.addWarningInformation(admin, faceLog.getCardid(), faceLog.getId());
                     }
+                    //推送闸机数据到第三方
+                    pushToThirdPartyService.sendToOther(faceDevice.getAdminId(),faceLog,base64Photo);
                 }
 
                 try {

+ 94 - 0
src/main/java/com/yx/face/service/impl/PushToThirdPartyServiceImpl.java

@@ -0,0 +1,94 @@
+package com.yx.face.service.impl;
+
+import com.alibaba.excel.util.StringUtils;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.yx.face.boot.uitls.DateUtils;
+import com.yx.face.boot.uitls.OkHttpUtils;
+import com.yx.face.dao.FaceDeviceDao;
+import com.yx.face.model.dto.BiJieGADto;
+import com.yx.face.model.entity.FaceDevice;
+import com.yx.face.model.entity.FaceLog;
+import com.yx.face.service.PushToThirdPartyService;
+import com.yx.face.utils.Sm4Util;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Objects;
+
+
+/**
+ * @description: 发送给第三方
+ * @date: 2024/12/11 >
+ * @author: LSH
+ */
+
+@Service
+@Slf4j
+public class PushToThirdPartyServiceImpl implements PushToThirdPartyService {
+
+    //毕节公安
+    @Value("${push-to-third-party.bijiega-url}")
+    private String biJieGAUrl;
+    //毕节公安
+    @Value("${push-to-third-party.bijiega-key}")
+    private String biJieSm4Key;
+
+    @Resource
+    private FaceDeviceDao faceDeviceDao;
+
+    @Override
+    public void sendToOther(Integer adminId, FaceLog faceLog, String photo) {
+        try {
+            if (83 == adminId) {
+                this.sendToBiJie(faceLog, photo);
+            }
+        } catch (Exception e) {
+            log.error("推送到第三方异常:" + e.getMessage());
+        }
+    }
+
+    /**
+     * 推送毕节闸机数据到毕节公安
+     * @param faceLog
+     * @param photo
+     */
+    private void sendToBiJie(FaceLog faceLog, String photo) {
+
+        FaceDevice faceDevice = faceDeviceDao.getFaceDeviceBySn(faceLog.getDeviceSn());
+        BiJieGADto biJieDto = new BiJieGADto();
+
+        biJieDto.setId(faceLog.getId().toString());
+        biJieDto.setName(StringUtils.isEmpty(faceLog.getName()) ? "未记录" : faceLog.getName());
+        biJieDto.setZjhm(faceLog.getCardid());
+        biJieDto.setZjlx(faceLog.getSfzCardType());
+        if (Objects.nonNull(faceDevice) && !StringUtils.isEmpty(faceDevice.getName())) {
+            biJieDto.setZjmc(faceDevice.getName());
+        }
+        biJieDto.setZjdz(faceLog.getDeviceSn());
+        biJieDto.setTgtime(faceLog.getFaceTime());
+        biJieDto.setZjbh(faceLog.getDeviceSn());
+        biJieDto.setTstime(DateUtils.dateTimeNow());
+        String bijieData = JSON.toJSONString(biJieDto);
+        log.info("推送给毕节公安数据:" + bijieData);
+        biJieDto.setImage(photo);
+        bijieData = JSON.toJSONString(biJieDto);
+        String encStr = Sm4Util.encryptByHexKey(bijieData, biJieSm4Key);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("data", encStr);
+        String body = JSON.toJSONString(jsonObject);
+
+        String result = OkHttpUtils.builder().url(biJieGAUrl).localPost(body).sync();
+        log.info("推送到毕节公安响应结果:{}",result);
+        if (!"5".equals(result)){
+            throw new RuntimeException("推送到毕节公安异常:" + result);
+        }else {
+            log.info("推送到毕节公安,姓名:{},身份证:{}", faceLog.getName(), faceLog.getCardid());
+        }
+    }
+
+
+}
+

+ 80 - 0
src/main/java/com/yx/face/utils/Sm4Util.java

@@ -0,0 +1,80 @@
+package com.yx.face.utils;
+
+import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.core.util.HexUtil;
+import cn.hutool.crypto.Mode;
+import cn.hutool.crypto.Padding;
+import cn.hutool.crypto.SmUtil;
+import cn.hutool.crypto.symmetric.SM4;
+
+import javax.crypto.SecretKey;
+
+/**
+ * SM4加解密工具类
+ * @Author lsh
+ * @date 2024/12/13
+ */
+public class Sm4Util {
+
+    /**
+     * 获取sm4秘钥
+     *
+     * @return sm4秘钥
+     */
+    public static String getSm4Key() {
+        SM4 sm4 = SmUtil.sm4();
+        SecretKey secretKey = sm4.getSecretKey();
+        byte[] encoded = secretKey.getEncoded();
+        return HexUtil.encodeHexStr(encoded);
+    }
+
+    /**
+     * sm4加密 key长度32位字符
+     *
+     * @param content 文本
+     * @param sm4Key  sm4秘钥
+     * @return 加密后的结果
+     */
+    public static String encrypt(String content, String sm4Key) {
+        SM4 sm4 = new SM4(HexUtil.decodeHex(sm4Key));
+        return sm4.encryptHex(content);
+    }
+
+    /**
+     * sm4解密 key长度32位字符
+     * @param content
+     * @param sm4Key
+     * @return 解密后的结果
+     */
+    public static String decrypt(String content, String sm4Key) {
+        SM4 sm4 = new SM4(HexUtil.decodeHex(sm4Key));
+        return sm4.decryptStr(content);
+    }
+
+
+    /**
+     * sm4 16进制key加密 key长度16位字符
+     *
+     * @param content 文本
+     * @param sm4Key  sm4秘钥
+     * @return 加密后的结果
+     */
+    public static String encryptByHexKey(String content, String sm4Key) {
+        SM4 sm4 = new SM4(Mode.ECB, Padding.PKCS5Padding, sm4Key.getBytes());
+        byte[] encrypt = sm4.encrypt(content);
+        return HexUtil.encodeHexStr(encrypt);
+    }
+
+
+    /**
+     * sm4 16进制key解密 key长度16位字符
+     * @param content
+     * @param sm4Key
+     * @return 解密后的结果
+     */
+    public static String decryptByHexKey(String content, String sm4Key) {
+        SM4 sm4 = new SM4(Mode.ECB, Padding.PKCS5Padding, sm4Key.getBytes());
+        return sm4.decryptStr(content, CharsetUtil.CHARSET_UTF_8);
+    }
+
+}

+ 6 - 0
src/main/resources/application-prod.yml

@@ -129,3 +129,9 @@ scan:
       batchCreateUrl: https://api.jiandaoyun.com/api/v5/app/entry/data/batch_create
       #查询记录是否存在
       queryListUrl: https://api.jiandaoyun.com/api/v5/app/entry/data/list
+
+##---------------------------------------推送第三方数据url配置--------------------------------------------------
+push-to-third-party:
+  #毕节公安
+  bijiega-url: http://58.16.186.83:23812/api/values/PerData
+  bijiega-key: 1dc53232bb3a99f9

+ 5 - 1
src/main/resources/application-test.yml

@@ -126,7 +126,11 @@ scan:
       queryListUrl: https://api.jiandaoyun.com/api/v5/app/entry/data/list
 
 
-
+##---------------------------------------推送第三方数据url配置--------------------------------------------------
+push-to-third-party:
+  #毕节公安
+  bijiega-url: http://58.16.186.83:23812/api/values/PerData
+  bijiega-key: 1dc53232bb3a99f9