diff --git a/laws-base/laws-base-core/pom.xml b/laws-base/laws-base-core/pom.xml
index 6d6b9da6..69cbfcd6 100644
--- a/laws-base/laws-base-core/pom.xml
+++ b/laws-base/laws-base-core/pom.xml
@@ -261,6 +261,10 @@
p6spy
p6spy
+
+ org.springframework
+ spring-test
+
\ No newline at end of file
diff --git a/laws-base/laws-base-core/src/main/java/com/jero/common/util/IntekeyUtils.java b/laws-base/laws-base-core/src/main/java/com/jero/common/util/IntekeyUtils.java
index eadfb9da..b1c662f7 100644
--- a/laws-base/laws-base-core/src/main/java/com/jero/common/util/IntekeyUtils.java
+++ b/laws-base/laws-base-core/src/main/java/com/jero/common/util/IntekeyUtils.java
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.*;
+import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -33,23 +34,46 @@ public class IntekeyUtils {
public void setEnable(boolean enable) {
ENABLE = enable;
}
+
@Value("${download.decrypt.url}")
public void setDecryptUrl(String decryptUrl) {
DECRYPT_URL = decryptUrl;
}
+
@Value("${download.decrypt.app_code}")
public void setDecryptAppCode(String decryptAppCode) {
DECRYPT_APP_CODE = decryptAppCode;
}
+
@Value("${download.decrypt.secret_key}")
public void setDecryptSecretKey(String decryptSecretKey) {
DECRYPT_SECRET_KEY = decryptSecretKey;
}
+ public static MultipartFile autoDecryptFile(MultipartFile file) {
+ if (!ENABLE || file == null) {
+ return file;
+ }
+
+ // 将文件解密
+ InputStream inputStream;
+ try {
+ inputStream = IntekeyUtils.decryptFile(DECRYPT_URL, DECRYPT_APP_CODE, DECRYPT_SECRET_KEY, null, file);
+ return new MockMultipartFile(
+ file.getName(),
+ file.getOriginalFilename(),
+ file.getContentType(),
+ inputStream);
+ } catch (Exception e) {
+ log.error("文件解密失败,返回原文件");
+ return file;
+ }
+ }
+
+
/**
* 解密文件,返回InputStream,供excel使用
*
- *
* @param url
* @param multipartFile
* @return
@@ -78,7 +102,7 @@ public class IntekeyUtils {
HttpEntity> files = new HttpEntity<>(form, headers);
System.out.println(url);
ResponseEntity entity = restTemplate.exchange(url, HttpMethod.POST, files, byte[].class);
- System.out.println(entity.getStatusCode().value() + ","+ entity.getStatusCode().getReasonPhrase() + "," + Objects.requireNonNull(entity.getBody()).length);
+ System.out.println(entity.getStatusCode().value() + "," + entity.getStatusCode().getReasonPhrase() + "," + Objects.requireNonNull(entity.getBody()).length);
byte[] body = entity.getBody();
InputStream sbs = new ByteArrayInputStream(body);
return sbs;
@@ -93,12 +117,12 @@ public class IntekeyUtils {
if (StrUtil.isNotBlank(originalFilename) && originalFilename.contains("%")) {
originalFilename = java.net.URLDecoder.decode(originalFilename, "UTF-8");
}
- log.info("originalFilename:"+originalFilename);
+ log.info("originalFilename:" + originalFilename);
int index = originalFilename.lastIndexOf(".");
//String[] filename = originalFilename.split("\\.");
- if (index != -1){
+ if (index != -1) {
file = File.createTempFile(originalFilename.substring(0, index), originalFilename.substring(index + 1));
- }else {
+ } else {
file = File.createTempFile(originalFilename, null);
}
file.delete();
@@ -111,7 +135,7 @@ public class IntekeyUtils {
}
public static InputStream getInputStreamByDecryptFile(MultipartFile file) {
- if(ENABLE){
+ if (ENABLE) {
return decryptFile(DECRYPT_URL, DECRYPT_APP_CODE, DECRYPT_SECRET_KEY, null, file);
}
try {