From a4dd111def5ffb9f89df206a2072d87ea2017b97 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sun, 20 Mar 2022 23:30:53 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E9=87=8D=E5=86=99jodd=E5=BC=BA=E5=88=B6=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BaseWxPayServiceImpl.java | 6 ++-- .../binarywang/wxpay/util/ZipUtils.java | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index ae40210c8..47b898720 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -20,13 +20,13 @@ import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.*; import com.github.binarywang.wxpay.util.SignUtils; import com.github.binarywang.wxpay.util.XmlConfig; +import com.github.binarywang.wxpay.util.ZipUtils; import com.github.binarywang.wxpay.v3.util.AesUtils; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import jodd.io.ZipUtil; import me.chanjar.weixin.common.error.WxRuntimeException; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -888,7 +888,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { Path path = Paths.get(tempDirectory.toString(), System.currentTimeMillis() + ".gzip"); Files.write(path, responseBytes); try { - List allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); + List allLines = Files.readAllLines(ZipUtils.unGzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { @@ -941,7 +941,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { Files.write(path, responseBytes); try { - List allLines = Files.readAllLines(ZipUtil.ungzip(path.toFile()).toPath(), StandardCharsets.UTF_8); + List allLines = Files.readAllLines(ZipUtils.unGzip(path.toFile()).toPath(), StandardCharsets.UTF_8); return Joiner.on("\n").join(allLines); } catch (ZipException e) { if (e.getMessage().contains("Not in GZIP format")) { diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java new file mode 100644 index 000000000..f9c434196 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/util/ZipUtils.java @@ -0,0 +1,33 @@ +package com.github.binarywang.wxpay.util; + +import lombok.experimental.UtilityClass; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.zip.GZIPInputStream; + +/** + * @author Binary Wang + */ +@UtilityClass +public class ZipUtils { + + /** + * 解压gzip文件 + */ + public static File unGzip(final File file) throws IOException { + File resultFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())); + resultFile.createNewFile(); + + try (FileOutputStream fos = new FileOutputStream(resultFile); + GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(file));) { + IOUtils.copy(gzis, fos); + } + + return resultFile; + } +}