工行压缩修改过后的版本
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package icbc;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONConverter;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.icbc.api.DefaultIcbcClient;
|
||||
@@ -14,6 +18,7 @@ import com.icbc.api.response.MybankEnterpriseSalaryFinancialofficeMesfinstrsubmi
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -67,15 +72,15 @@ public class IcbcTest {
|
||||
bizContent.setfSeqNo(seqNo);
|
||||
ArrayList<MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestV1.MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestRdV1> list = new ArrayList<>();
|
||||
|
||||
for(int i = 1;i <= 3;i++) {
|
||||
// for(int i = 1;i <= 3;i++) {
|
||||
MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestV1.MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestRdV1 rd =
|
||||
new MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestV1.MybankEnterpriseSalaryFinancialofficeMesfinstrsubmitRequestRdV1();
|
||||
rd.setAmount(1L);
|
||||
rd.setPostscript("第[" + i + "]笔工资");
|
||||
rd.setPostscript("第[" + 1 + "]笔工资");
|
||||
rd.setBusiCode("");
|
||||
rd.setCurrency("CNY");
|
||||
rd.setPurpose("工资");
|
||||
rd.setSummary("第[" + i + "]笔工资");
|
||||
rd.setSummary("第[" + 1 + "]笔工资");
|
||||
rd.setSummaryEn("Salary");
|
||||
rd.setPayerAccount("0200080609200100843");
|
||||
rd.setPayerCnname("榔右蝗呵如咪仔牌芝降化僵侦柱");
|
||||
@@ -96,10 +101,16 @@ public class IcbcTest {
|
||||
rd.setOriVoucherNo("");
|
||||
rd.setOriVoucherType("");
|
||||
list.add(rd);
|
||||
}
|
||||
// }
|
||||
// bizContent.setRd(list);
|
||||
|
||||
// if(bizContent.getRd().size() >= 2) {
|
||||
bizContent.setZipFlag("1");
|
||||
// }
|
||||
|
||||
/** RD 转 Json串 */
|
||||
String json = JSONUtil.toJsonPrettyStr(list);
|
||||
// json = "rd:" + json;
|
||||
log.info("Json:\n{}",json);
|
||||
|
||||
/** 将Json用zip压缩 */
|
||||
@@ -107,11 +118,11 @@ public class IcbcTest {
|
||||
// 用Zip压缩
|
||||
// zipStr = ZipTools.zip(json.getBytes(StandardCharsets.UTF_8));
|
||||
// 用GZip压缩
|
||||
// zipStr = IcbcTools.gzip(json.getBytes(StandardCharsets.UTF_8));
|
||||
// zipStr = ZipTools.gzip(json.getBytes(StandardCharsets.UTF_8));
|
||||
// 用JZip压缩
|
||||
zipStr = ZipTools.jzip(json.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
bizContent.setZipFlag("1");
|
||||
// bizContent.setZipFlag("1");
|
||||
bizContent.setZip(zipStr);
|
||||
|
||||
request.setServiceUrl(baseURL + "/" + URI);
|
||||
@@ -154,21 +165,34 @@ public class IcbcTest {
|
||||
bizContent.setfSeqNo(seqNo);
|
||||
request.setServiceUrl(baseURL + "/" + URI);
|
||||
request.setBizContent(bizContent);
|
||||
bizContent.setQryFSeqNo("202103050000000009");
|
||||
|
||||
// bizContent.setQryFSeqNo("20210709104459897471");
|
||||
bizContent.setQryFSeqNo("20210709103955492472");
|
||||
// bizContent.setQryFSeqNo("202103050000000009");
|
||||
|
||||
log.info("request:{}",JSONUtil.toJsonStr(request));
|
||||
|
||||
MybankEnterpriseSalaryFinancialofficeMesfinstrqryResponseV1 response = client.execute(request);
|
||||
|
||||
// Console.log("rs:{}",response);
|
||||
log.info("response:{}",JSONUtil.toJsonPrettyStr(response));
|
||||
if (response.isSuccess()) {
|
||||
// 业务成功处理
|
||||
System.out.println("success");
|
||||
log.info("response:{}",JSONUtil.toJsonPrettyStr(response));
|
||||
|
||||
// 业务成功处理
|
||||
if(StrUtil.equals(response.getZipFlag(),"1")) {
|
||||
String zipStr = ZipTools.unjzip(response.getZip());
|
||||
// Console.log("zipStr:{}",zipStr);
|
||||
// ArrayList arrayList = new ArrayList();
|
||||
JSONArray array = JSONUtil.parseArray(zipStr);
|
||||
response.setRd(JSONUtil.toList(array,MybankEnterpriseSalaryFinancialofficeMesfinstrqryResponseV1.MybankEnterpriseSalaryFinancialofficeMesfinstrqryResponseRdV1.class));
|
||||
response.setZip(null);
|
||||
// Console.log("array:" + array);
|
||||
}
|
||||
// else{
|
||||
//
|
||||
// }
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
BeanUtil.beanToMap(response,map,true,true);
|
||||
log.info("map:{}",map);
|
||||
|
||||
// log.info("map:{}",map);
|
||||
JSONConverter convert = new JSONConverter();
|
||||
JSON json = convert.convert(map,null);
|
||||
log.info("response:{}",JSONUtil.toXmlStr(json));
|
||||
@@ -182,4 +206,27 @@ public class IcbcTest {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// String str =
|
||||
// "H4sIAAAAAAAAAH1Uz2sTQRS+C/4PIWeFmd1suutRD968eBKRYbo7jUuzPzq7Wwjiwb8lhzYRi7Gp\n" +
|
||||
// "NTGU0hrINqJr4jYItQdF9OJBQehBxJnN0rSb2cxpHt/3vnnvezNDjcKNwv2rVwrpejTb8hXYJloO\n" +
|
||||
// "PBOZnFdk4U0W3SVrsHjtMtNEHllDtsNpItzTHxIjqBJkYJ9wkgQkAGRJyRJdXEN+zU04cyoMJBRh\n" +
|
||||
// "XXcC2+cMLgI0TQWaBMtALWtS+bqqQQhkAEribN22sZXIx8PXG52T3gjFw3e/Xnw5+jjZHB+Kk8h5\n" +
|
||||
// "Uha3sI0rXBZTI+1fUxRVVZLSAFySJdbq4qxU+k1vexD3Dv5uD7r9V53w+4d455moHHLRASgvSXIJ\n" +
|
||||
// "lqAiCRsmFxre/fryT/u0NZic7G89j/Z/1Def3A7P6o320fGn8He4Jc7P79100EoVV4Sj8lgO0k2/\n" +
|
||||
// "lk+Zyi8c9lSCw63WXkPMWMb2aup8CUiKzH2XYI4ZU3LaT/cfU60f9vuN9rfw7WhndBZFnXD38zh6\n" +
|
||||
// "f9p5Otw7+NkdH29EUVZKDygltp7UdevOvSyMrXQ4EIBsEQF1HY915RhCR1OcQ5NmPJwzNbAsTJNz\n" +
|
||||
// "4+aomQOziXFGGs0d4Xi+p1PTTa7PLMryKFlJXZ1HquwRGyifQajL/gNq4uoCAvsR9NUcPPl08kxy\n" +
|
||||
// "qInWnYDl0/Pbs4gjPuISI+eCu5S9NdelznpuJ5RUAmaH6dgoO1xQnFEfT7cP/gMM28fScQUAAA== ";
|
||||
|
||||
String str2 = "UEsDBBQACAgIAFRS6VIAAAAAAAAAAAAAAAABAAAAfo1Su04CQRTt+QqytcXMLk87JVpSiDExhGJcRtzIzqyzu8XGWPhoNBiiIRgLQiWFoTGEWGj4GobHXzizQJgFjN5ic3PPmXMfe4qxuIjL8CtDc33bRizQtuPauNstwtK42+Cfb5P+nba1ZDF8mqeSowMdgjTIQgAzCWAAkadVooMCjHOEIBtL+rTd49f10fdA5SCb+sQTMFQf+syhbvhovb1UZUvVUafB671J64U/9Xnnhj+/D78a4/va5KE1fX3ktSa/7Q8HnVH7IyJCXc81meV4fyxLmXVEffMMs9nOKmYjgipiFsTK6+CJ71o5WsardUVwvsFvkhvg2UUtL9gEsB3TnB9TAzoAIANSICsSKNKEsUI/DJxQPlKfG2CPSKSAqtIMq+13ETmfrWuATFL8eBHQ2LzioomKWnS/iiqhfyLlAr74n61MnzFMzPAGufzx2oDKGVI61PWUPAbMpoEcNRl1chV5uHywMLQWQlex0g9QSwcIkEzkJm8BAAAaAwAAUEsBAhQAFAAICAgAVFLpUpBM5CZvAQAAGgMAAAEAAAAAAAAAAAAAAAAAAAAAAH5QSwUGAAAAAAEAAQAvAAAAngEAAAAA";
|
||||
String str = "UEsDBBQACAgIABVV+VIAAAAAAAAAAAAAAAABAAAAfn1SwW4TMRD9lz33YG92kyxXOHPhhKrKcnfdYJG1U3uNFCEOlFKpEJQCoaiCqqoEOaBwQFWgUqFfE282f4G962ySS32y3ryZN/Nmtp97PdwnBO1i9hQx7t3zGqAdtgNgHmx4Wy4cM4ZTYqKLiyv9cpj/vTUhQbo4IwkSZK9KtXQlelxapv7zvZgeWojLTMaC9jKDzieTbbgzn4xW4TX9SiN/+0V/Olp8/F1cDoqDy9nNv/zr8eLsRL+e6OG1SeGComdcxU+IQFm/RyrpddRVKpuUqmuVI6clEI5jrpjFgG/GbIMmiMwHmm9gR5YqTbHoI8IM5RHumr9FTcmYZn2018UdE4AG2zcsLhIryB3k/DLEpT5Nd5WQpLZoo0+HxUoIwmKbc//hYwNQ42qGYp7YMUBVdzmr7bH0y1IyWk7qAx+Clh9CEAA/sAQl6TK/rpfKjltTaUS91Xw80sOr4vyzfj/V4wP94cfsZjQ/HhRvzhdn7/TgVL+azm7H+cUvW4rJTKyVqxalvx3OT45m1z+tVRkWGUrMcVRqztA71r9aSdOHvt+0i4FRC9g7DA0Lp1UYbnkpZrhjm8ciqf1TjKJyYpq4eflyT/5KRBBcW2peuR13upV/IIKgEYVhFDZaQcstmCJJ9u9kVW4Strq6zSZreK0U3LwNlTpGba5r9AEIgrb3Yuc/UEsHCDuqhyIDAgAAqgMAAFBLAQIUABQACAgIABVV+VI7qociAwIAAKoDAAABAAAAAAAAAAAAAAAAAAAAAAB+UEsFBgAAAAABAAEALwAAADICAAAAAA==";
|
||||
|
||||
|
||||
Console.log("解压:\n{}",ZipTools.unjzip(str));
|
||||
// Console.log("解压:\n{}",ZipTools.unjzip(str2));
|
||||
|
||||
// Console.log("解压后:\n{}",ZipTools.ungzip(str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,13 +103,18 @@ public class ZipTools {
|
||||
ZipOutputStream zos = new ZipOutputStream(baos);
|
||||
zos.putNextEntry(new ZipEntry("~"));
|
||||
zos.write(src);
|
||||
zos.close();
|
||||
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
||||
}
|
||||
public static String unjzip(String src) throws IOException {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(src));
|
||||
InputStream is = new ZipInputStream(bais);
|
||||
String rs = IOUtils.toString(is);
|
||||
is.close();
|
||||
ZipInputStream zis = new ZipInputStream(bais);
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
if(null == zipEntry) {
|
||||
throw new IOException();
|
||||
}
|
||||
String rs = IOUtils.toString(zis);
|
||||
zis.close();
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user