108 lines
3.6 KiB
Java
108 lines
3.6 KiB
Java
package hro;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.XmlUtil;
|
|
import cn.hutool.crypto.SecureUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import ctg.entity.api.Api;
|
|
import ctg.entity.api.DiskApplyRequest;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.junit.jupiter.api.Test;
|
|
import ctg.tool.DataFactory;
|
|
import ctg.tool.DiskTool;
|
|
import ctg.tool.FastDFS;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
|
|
import net.lingala.zip4j.ZipFile;
|
|
import net.lingala.zip4j.exception.ZipException;
|
|
import net.lingala.zip4j.model.ZipParameters;
|
|
import net.lingala.zip4j.model.enums.AesKeyStrength;
|
|
import net.lingala.zip4j.model.enums.EncryptionMethod;
|
|
import org.w3c.dom.Document;
|
|
|
|
import javax.xml.xpath.XPathConstants;
|
|
|
|
|
|
/**
|
|
* @Author: Alawn
|
|
* @Description:
|
|
* @Date: Create in 10:45 上午 2021/2/7
|
|
*/
|
|
|
|
@Slf4j
|
|
public class DiskApplyRequestTest {
|
|
|
|
private final static String baseURL = "http://172.17.20.91:9998/api";
|
|
// private final static String baseURL = "http://127.0.0.1:8888/api";
|
|
private final static String secretKey = "HelloWorld";
|
|
private final static String zipPassword = "1234567";
|
|
|
|
@Test
|
|
public void simpleTest() throws Exception {
|
|
|
|
DiskApplyRequest request = DiskApplyRequest.builder()
|
|
.applyDate(DateUtil.format(new Date(),"YYYYMMdd"))
|
|
.customerId(DataFactory.randomCustomerId())
|
|
.titleId(DataFactory.randomTitleId())
|
|
.diskDesc("代发工资").build();
|
|
|
|
File file = DiskTool.newSimpleDiskFile(request.getCustomerId(),request.getTitleId(),"代发工资",10,new BigDecimal(50000.00));
|
|
request.setDiskNo(file.getName());
|
|
log.info("disk:{}", file.getAbsolutePath());
|
|
|
|
/** 文件压缩 */
|
|
if(!file.exists() || !file.isFile()) {
|
|
throw new FileNotFoundException();
|
|
}
|
|
|
|
File disk = new File(file.getParent() + "/" + file.getName() + ".zip");
|
|
|
|
try {
|
|
if ("".equals(zipPassword)) {
|
|
ZipParameters zipParameters = new ZipParameters();
|
|
zipParameters.setEncryptFiles(true);
|
|
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
|
|
zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
|
|
new ZipFile(disk, zipPassword.toCharArray()).addFile(file, zipParameters);
|
|
}
|
|
else {
|
|
new ZipFile(disk).addFile(file);
|
|
}
|
|
}
|
|
catch (ZipException e) {
|
|
System.err.println(e);
|
|
}
|
|
|
|
/** 上传文件 */
|
|
String fid = FastDFS.upload(disk);
|
|
log.debug("fid:{}",fid);
|
|
request.setFilePath(fid);
|
|
request.setFileVersion("");
|
|
request.setFilePath(fid);
|
|
request.setMd5(SecureUtil.md5(disk));
|
|
|
|
/** 送盘请求 */
|
|
Api<DiskApplyRequest> api = new Api<>("diskApply",request);
|
|
|
|
log.info("request:{}",api.toData());
|
|
log.debug("signature:{}",api.signature());
|
|
|
|
String response = HttpUtil.createPost(baseURL).header("Signature",api.signature()).body(api.toData()).setConnectionTimeout(3000).timeout(3000).execute().body();
|
|
// String response = HttpUtil.createPost(baseURL).header("Signature","lkajsdfkljaslkdfjklasdjfk").body(api.toData()).setConnectionTimeout(3000).timeout(3000).execute().body();
|
|
|
|
log.info("response:{}",response);
|
|
|
|
Document doc = XmlUtil.readXML(response);
|
|
|
|
String respCode = (String) XmlUtil.getByXPath("//root/head/respCode",doc, XPathConstants.STRING);
|
|
String respMessage = (String) XmlUtil.getByXPath("//root/head/respMessage",doc, XPathConstants.STRING);
|
|
|
|
log.info("[{}]:[{}]",respCode,respMessage);
|
|
}
|
|
}
|
|
|