Skip to content

Commit a4dd111

Browse files
committed
🎨 优化代码,重写jodd强制依赖的代码
1 parent 94e6d65 commit a4dd111

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import com.github.binarywang.wxpay.service.*;
2121
import com.github.binarywang.wxpay.util.SignUtils;
2222
import com.github.binarywang.wxpay.util.XmlConfig;
23+
import com.github.binarywang.wxpay.util.ZipUtils;
2324
import com.github.binarywang.wxpay.v3.util.AesUtils;
2425
import com.google.common.base.Joiner;
2526
import com.google.common.collect.ImmutableMap;
2627
import com.google.common.collect.Maps;
2728
import com.google.gson.Gson;
2829
import com.google.gson.GsonBuilder;
29-
import jodd.io.ZipUtil;
3030
import me.chanjar.weixin.common.error.WxRuntimeException;
3131
import org.apache.commons.lang3.StringUtils;
3232
import org.slf4j.Logger;
@@ -888,7 +888,7 @@ private String handleGzipBill(String url, String requestStr) throws WxPayExcepti
888888
Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip");
889889
Files.write(path, responseBytes);
890890
try {
891-
List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8);
891+
List<String> allLines = Files.readAllLines(ZipUtils.unGzip(path.toFile()).toPath(), StandardCharsets.UTF_8);
892892
return Joiner.on("\n").join(allLines);
893893
} catch (ZipException e) {
894894
if (e.getMessage().contains("Not in GZIP format")) {
@@ -941,7 +941,7 @@ private String handleGzipFundFlow(String url, String requestStr) throws WxPayExc
941941
Files.write(path, responseBytes);
942942

943943
try {
944-
List<String> allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8);
944+
List<String> allLines = Files.readAllLines(ZipUtils.unGzip(path.toFile()).toPath(), StandardCharsets.UTF_8);
945945
return Joiner.on("\n").join(allLines);
946946
} catch (ZipException e) {
947947
if (e.getMessage().contains("Not in GZIP format")) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.github.binarywang.wxpay.util;
2+
3+
import lombok.experimental.UtilityClass;
4+
import org.apache.commons.io.FilenameUtils;
5+
import org.apache.commons.io.IOUtils;
6+
7+
import java.io.File;
8+
import java.io.FileInputStream;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.util.zip.GZIPInputStream;
12+
13+
/**
14+
* @author Binary Wang
15+
*/
16+
@UtilityClass
17+
public class ZipUtils {
18+
19+
/**
20+
* 解压gzip文件
21+
*/
22+
public static File unGzip(final File file) throws IOException {
23+
File resultFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath()));
24+
resultFile.createNewFile();
25+
26+
try (FileOutputStream fos = new FileOutputStream(resultFile);
27+
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file));) {
28+
IOUtils.copy(gzis, fos);
29+
}
30+
31+
return resultFile;
32+
}
33+
}

0 commit comments

Comments
 (0)