Explorar o código

Merge branch 'V0.0.4' of http://10.87.21.221:8000/jzyd_yyds/soc into V0.0.4

jiawuxian hai 1 ano
pai
achega
cd281168eb

+ 27 - 4
soc-common/soc-common-security/src/main/java/com/xunmei/common/security/utils/SaltHelper.java

@@ -2,11 +2,16 @@ package com.xunmei.common.security.utils;
 
 
 import cn.hutool.core.codec.Base64;
+import cn.hutool.core.io.resource.ClassPathResource;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.util.UUID;
 
@@ -16,11 +21,12 @@ import java.util.UUID;
 @Slf4j
 public class SaltHelper {
 
-    private static final String KEY = "rDWBHusbFTlOURS4";
-
+   // private static final String KEY = "rDWBHusbFTlOURS4";
+    private static ClassPathResource resource = new ClassPathResource("key/privatekey.pri");
     public static String decryptAES(final String content) {
         try {
-            final SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
+            String Key =loadKeyFromFile(resource.getStream());
+            final SecretKeySpec skeySpec = new SecretKeySpec(Key.getBytes("UTF-8"), "AES");
             final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","CCM"); // "算法/模式/补码方式"
             cipher.init(Cipher.DECRYPT_MODE, skeySpec);
             return new String(cipher.doFinal(Base64.decode(content)));
@@ -32,7 +38,8 @@ public class SaltHelper {
 
     public static String encryptAES(final String content) {
         try {
-            final SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
+            String Key =loadKeyFromFile(resource.getStream());
+            final SecretKeySpec skeySpec = new SecretKeySpec(Key.getBytes("UTF-8"), "AES");
             final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","CCM"); // "算法/模式/补码方式"
             cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
             return Base64.encode(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
@@ -42,6 +49,22 @@ public class SaltHelper {
         }
     }
 
+    private static String loadKeyFromFile(InputStream inputStream) {
+        //将InputStream读入Reader中
+        Reader reader = new InputStreamReader(inputStream);
+        //实例化一个StringBuilder以保存结果
+        StringBuilder result = new StringBuilder();
+        //读取每个字节并转换为char,添加到StringBuilder
+        try {
+            for (int data = reader.read(); data != -1; data = reader.read()) {
+                result.append((char) data);
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        // 将文件内容转为字符串
+        return result.toString();
+    }
     /**
      * 比较相等
      *

+ 30 - 6
soc-common/soc-common-security/src/main/java/com/xunmei/common/security/utils/SecurityUtils.java

@@ -1,6 +1,7 @@
 package com.xunmei.common.security.utils;
 
 import cn.hutool.core.codec.Base64;
+import cn.hutool.core.io.resource.ClassPathResource;
 import cn.hutool.extra.spring.SpringUtil;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.constant.TokenConstants;
@@ -14,6 +15,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.nio.charset.StandardCharsets;
 import java.util.Optional;
 import java.util.UUID;
@@ -26,8 +31,8 @@ import java.util.UUID;
 public class SecurityUtils {
     private static final String[] deviceArray = new String[]{"iphone", "android", "ios", "harmonyos", "deviceInfo", "phone", "mobile", "wap", "netfront", "java", "opera mobi", "opera mini", "ucweb", "windows ce", "symbian", "series", "webos", "sony", "blackberry", "dopod", "nokia", "samsung", "palmsource", "xda", "pieplus", "meizu", "midp", "cldc", "motorola", "foma", "docomo", "up.browser", "up.link", "blazer", "helio", "hosin", "huawei", "novarra", "coolpad", "webos", "techfaith", "palmsource", "alcatel", "amoi", "ktouch", "nexian", "ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui", "smartphone", "iemobile", "spice", "bird", "zte-", "longcos", "pantech", "gionee", "portalmmm", "jig browser", "hiptop", "benq", "haier", "^lct", "320x320", "240x320", "176x220", "w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-"/*, "tosh"*/, "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-", "Googlebot-Mobile", "dart", "flutter", "xunmeiapp"};
 
-    private static final String KEY = "rDWBHusbFTlOURS4";
-
+    //private static final String KEY = "rDWBHusbFTlOURS4";
+    private static ClassPathResource resource = new ClassPathResource("key/privatekey.pri");
     /**
      * 获取用户ID
      */
@@ -118,9 +123,10 @@ public class SecurityUtils {
 
     public static String decryptAES(final String content) {
         try {
-            final SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
+            String Key =loadKeyFromFile(resource.getStream());
+            final SecretKeySpec skeySpec = new SecretKeySpec(Key.getBytes("UTF-8"), "AES");
             // "算法/模式/补码方式"
-            final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding","CCM");
+            final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","CCM");
             cipher.init(Cipher.DECRYPT_MODE, skeySpec);
             return new String(cipher.doFinal(Base64.decode(content)));
         } catch (final Exception e) {
@@ -128,11 +134,29 @@ public class SecurityUtils {
         }
     }
 
+    private static String loadKeyFromFile(InputStream inputStream) {
+        //将InputStream读入Reader中
+        Reader reader = new InputStreamReader(inputStream);
+        //实例化一个StringBuilder以保存结果
+        StringBuilder result = new StringBuilder();
+        //读取每个字节并转换为char,添加到StringBuilder
+        try {
+            for (int data = reader.read(); data != -1; data = reader.read()) {
+                result.append((char) data);
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        // 将文件内容转为字符串
+        return result.toString();
+    }
+
     public static String encryptAES(final String content) {
         try {
-            final SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
+            String Key =loadKeyFromFile(resource.getStream());
+            final SecretKeySpec skeySpec = new SecretKeySpec(Key.getBytes("UTF-8"), "AES");
             // "算法/模式/补码方式"
-            final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding","CCM");
+            final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding","CCM");
             cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
             return Base64.encode(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
         } catch (final Exception e) {

+ 1 - 0
soc-common/soc-common-security/src/main/resources/key/privatekey.pri

@@ -0,0 +1 @@
+rDWBHusbFTlOURS4

+ 2 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/drill/service/impl/CoreDrillTaskServiceImpl.java

@@ -60,6 +60,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLEncoder;
@@ -642,7 +643,7 @@ public class CoreDrillTaskServiceImpl extends ServiceImpl<CoreDrillTaskMapper, C
             registerBookPdf.setOrgName(task.getOrgName());
             registerBookPdf.setOrgPath(sysOrg.getPath());
             registerBookPdf.setFileUrl(pdfUrl);
-            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, "/"));
+            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, File.separator));
             registerBookPdfService.save(registerBookPdf);
 
 

+ 1 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/edu/service/impl/CoreEduTrainingTaskServiceImpl.java

@@ -709,7 +709,7 @@ public class CoreEduTrainingTaskServiceImpl extends ServiceImpl<CoreEduTrainingT
             registerBookPdf.setOrgName(task.getOrgName());
             registerBookPdf.setOrgPath(sysOrg.getPath());
             registerBookPdf.setFileUrl(pdfUrl);
-            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, "/"));
+            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, File.separator));
             registerBookPdfService.save(registerBookPdf);
         }, threadPoolTaskExecutor);
 

+ 2 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/AppPlanServiceImpl.java

@@ -54,6 +54,7 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.io.File;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
@@ -803,7 +804,7 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
             registerBookPdf.setOrgPath(sysOrg.getPath());
             registerBookPdf.setFileUrl(pdfUrl);
             //registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, "\\"));
-            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, "/"));
+            registerBookPdf.setFileName(StringUtils.substringAfterLast(pdfUrl, File.separator));
             if(StringUtils.isEmpty(registerBookPdf.getFileName())||StringUtils.isEmpty(pdfUrl)){
                 throw new SystemException(ErrorMsgConstants.GENERATE_PDF_ERROR);
             }

+ 1 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/safetyCheck/service/impl/CoreSafecheckPlanServiceImpl.java

@@ -639,7 +639,7 @@ public class CoreSafecheckPlanServiceImpl extends ServiceImpl<CoreSafecheckPlanM
         registerBookPdf.setOrgPath(org.getPath());
         registerBookPdf.setFileUrl(url);
         //registerBookPdf.setFileName(StringUtils.substringAfterLast(url, "\\"));
-        registerBookPdf.setFileName(StringUtils.substringAfterLast(url, "/"));
+        registerBookPdf.setFileName(StringUtils.substringAfterLast(url, File.separator));
         registerBookPdf.setOrgName(registerBookVo.getOrgName());
         if (StringUtils.isEmpty(url) || StringUtils.isEmpty(registerBookPdf.getFileName())) {
             throw new SystemException(ErrorMsgConstants.GENERATE_PDF_ERROR);

+ 7 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/weather/service/impl/WeatherWarningServiceImpl.java

@@ -188,8 +188,13 @@ public class WeatherWarningServiceImpl extends ServiceImpl<WeatherWarningMapper,
     private List<WeatherWarning> buildWeatherWarningList(String str) {
         JSONObject obj = JSON.parseObject(str);
         //福建农信返回的数据外面多了一层(Data层为农信添加的,需要多取一层)
-        JSONObject objectNX = obj.getJSONObject("Data");
-        JSONObject resBody =objectNX.getJSONObject("showapi_res_body");
+        JSONObject resBody = null;
+        if(obj.containsKey("Data")){
+            JSONObject objectNX = obj.getJSONObject("Data");
+            resBody =objectNX.getJSONObject("showapi_res_body");
+        }else{
+            resBody =obj.getJSONObject("showapi_res_body");
+        }
         //JSONObject resBody =obj.getJSONObject("showapi_res_body");
         List<WeatherWarning> list = new ArrayList<>();
         if(resBody!=null){