Просмотр исходного кода

提交base64编译报错的bug

hxl13994548489 2 лет назад
Родитель
Сommit
2ed72023d5

+ 13 - 0
src/main/java/com/ydtech/modules/order/entity/api/pingan/utils/Base64Convert.java

@@ -20,4 +20,17 @@ public class Base64Convert {
     public static String byteToBase64(byte[] data) {
         return Base64.encodeBase64String(data);
     }
+
+    /**
+    * @Description 将base64为字符串转为字节数组
+    * @Author  hxl
+    * @Date   2024/4/2 16:28
+    * @Param
+    * @Return
+    * @Exception
+    *
+    */
+    public static byte[] encodeToString(String base64Str) {
+        return Base64.decodeBase64(base64Str);
+    }
 }

+ 1 - 3
src/main/java/com/ydtech/modules/order/entity/api/pingan/utils/PDFUtil.java

@@ -1,7 +1,6 @@
 package com.ydtech.modules.order.entity.api.pingan.utils;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
-import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;
 
 import java.io.*;
@@ -40,10 +39,9 @@ public class PDFUtil {
         BufferedInputStream bin = null;
         FileOutputStream fout = null;
         BufferedOutputStream bout = null;
-        BASE64Decoder decoder = new BASE64Decoder();
         try {
             //将base64编码的字符串解码成字节数组
-            byte[] bytes = decoder.decodeBuffer(base64sString);
+            byte[] bytes = Base64Convert.encodeToString(base64sString);
             //创建一个将bytes作为其缓冲区的ByteArrayInputStream对象
             ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             //创建从底层输入流中读取数据的缓冲输入流对象