|
@@ -1,5 +1,8 @@
|
|
|
package org.springblade.evisa.service.impl;
|
|
|
|
|
|
+import cfca.com.itextpdf.text.Image;
|
|
|
+import cfca.com.itextpdf.text.Rectangle;
|
|
|
+import cfca.com.itextpdf.text.pdf.PdfReader;
|
|
|
import cfca.paperless.ClientConstants;
|
|
|
import cfca.paperless.base.BaseConstants;
|
|
|
import cfca.paperless.base.util.Base64;
|
|
@@ -26,6 +29,7 @@ import cfca.paperless.dto.response.tx40.VerifyPdfSealResponse;
|
|
|
import cn.hutool.core.io.file.FileReader;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
@@ -534,13 +538,13 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(signPdfUrl));
|
|
|
|
|
|
//TODO ========== 执行电签 ==========
|
|
|
- Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
+ Object[] result = this.signPdfByAXQZ_2(pdfVO, fileByte, taskArchiveDTO.getType());
|
|
|
|
|
|
//返回结果集
|
|
|
if (result != null) {
|
|
|
if (result[0] != null) {
|
|
|
- //byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
- /*String dataUrl = "C:\\pdfFiles\\" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
+ /*byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
+ String dataUrl = "C:\\pdfFiles\\" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
File file1 = new File(dataUrl);
|
|
|
FileUtils.writeByteArrayToFile(file1, byteArray);*/
|
|
|
|
|
@@ -591,8 +595,11 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
//位置信息
|
|
|
signVO.setImageUrl(index.getUrl()); //固定签章
|
|
|
signVO.setSealType("2");//坐标签章
|
|
|
+
|
|
|
+ /*xy坐标后面构造签章策略时再计算
|
|
|
signVO.setLx(index.getLx()); //x轴
|
|
|
- signVO.setLy(index.getLy()); //y轴
|
|
|
+ signVO.setLy(index.getLy()); //y轴*/
|
|
|
+
|
|
|
signVO.setPage(index.getPage()); //page页码
|
|
|
sealStrategyVOS.add(signVO);
|
|
|
}
|
|
@@ -603,13 +610,13 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(signPdfUrl));
|
|
|
|
|
|
//TODO ========== 执行电签 ==========
|
|
|
- Object[] result = this.signPdfByAXQZ(pdfVO, fileByte);
|
|
|
+ Object[] result = this.signPdfByAXQZ_2(pdfVO, fileByte, taskArchiveDTO.getType());
|
|
|
|
|
|
//返回结果集
|
|
|
if (result != null) {
|
|
|
if (result[0] != null) {
|
|
|
- //byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
- /*String dataUrl = "C:\\pdfFiles\\" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
+ /*byte[] byteArray = IOUtils.toByteArray(new ByteArrayInputStream((byte[]) result[0]));
|
|
|
+ String dataUrl = "C:\\pdfFiles\\" + SnowFlakeUtil.getId() + ".pdf";
|
|
|
File file1 = new File(dataUrl);
|
|
|
FileUtils.writeByteArrayToFile(file1, byteArray);*/
|
|
|
|
|
@@ -878,6 +885,205 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
return sealStrategies;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安心2 - 签章 - 档案
|
|
|
+ */
|
|
|
+ private Object[] signPdfByAXQZ_2(SealPdfVO pdfVO, byte[] fileByte, int typeGenerate) {
|
|
|
+ Object[] result = new Object[3];
|
|
|
+ try {
|
|
|
+ PaperlessClient paperlessClient = new PaperlessClient(SIGN_HOST, SIGN_PORT, 300000, 36000000);
|
|
|
+ paperlessClient.setSSL(false);
|
|
|
+ //*****************************************************************************
|
|
|
+ CompoundSealPdfListDetachedRequest compoundSealPdfListDetachedRequest = new CompoundSealPdfListDetachedRequest();
|
|
|
+
|
|
|
+ RequestHead requestHead = new RequestHead();
|
|
|
+ //业务流水号 非空
|
|
|
+ String transactionNo = GUIDUtil.generateId();
|
|
|
+ //机构编码非空
|
|
|
+ String organizationCode = EVisaConstant.organizationCode;
|
|
|
+ //操作员编码 可为空(企业类型不能为空)
|
|
|
+ String operatorCode = EVisaConstant.operationCode;
|
|
|
+ //渠道编码 可为空
|
|
|
+ String channelCode = "";
|
|
|
+
|
|
|
+ //设置属性
|
|
|
+ requestHead.setBasicInfo(transactionNo, organizationCode, operatorCode, channelCode);
|
|
|
+
|
|
|
+ compoundSealPdfListDetachedRequest.setHead(requestHead);
|
|
|
+
|
|
|
+ //*****************************************************************************
|
|
|
+ CompoundSealPdfListRequestBody requestBody = new CompoundSealPdfListRequestBody();
|
|
|
+
|
|
|
+ List<PdfBean> pdfBeans = new ArrayList<>();
|
|
|
+ PdfBean pdfBean = new PdfBean();
|
|
|
+ pdfBean.setBizSerialNo(GUIDUtil.generateId());
|
|
|
+ pdfBean.setInputSource("");
|
|
|
+ pdfBean.setInputType(BaseConstants.INPUT_TYPE_FILEDATA);
|
|
|
+ pdfBean.setPdfData(fileByte);
|
|
|
+ pdfBeans.add(pdfBean);
|
|
|
+
|
|
|
+ requestBody.setPdfBeans(pdfBeans);
|
|
|
+
|
|
|
+ //重新获取文件流,计算xy坐标进行签章
|
|
|
+ ByteArrayInputStream pdfInputStream = new ByteArrayInputStream(fileByte);
|
|
|
+ PdfReader reader = new PdfReader(pdfInputStream);
|
|
|
+
|
|
|
+ //***********************构造机构章策略 ********************************
|
|
|
+ List<SealStrategy> sealStrategies = this.generateSealStrategies_2(pdfVO.getStrategyVoList(), reader, typeGenerate);
|
|
|
+
|
|
|
+ if (null == sealStrategies || sealStrategies.size() <= 0) {
|
|
|
+ logger.info("【电签模块】{}", "签章策略为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ requestBody.setSealStrategies(sealStrategies);
|
|
|
+
|
|
|
+ //签章后文件保存地址,不为空时,直接将签章文件保存在此地址,不再返回签章后文档数据;ftp:auto
|
|
|
+ requestBody.setOutputFilepath("");
|
|
|
+
|
|
|
+ //时间戳方式,默认为0;0:实时访问CFCA 时间戳服务;1:使用从CFCA购置并在本地部署的时间戳服务器产品;
|
|
|
+ requestBody.setTimestampChannel(BaseConstants.TIME_STAMP_CHANNEL_CFCA);
|
|
|
+ //获取场景证书的方式默认值为0;0:实时从CFCA CA服务申请下载场景证书;1:使用从CFCA CA服务预先申请下载并存储在本地的场景证书;
|
|
|
+ requestBody.setSceneCertChannel(BaseConstants.SCEND_CERT_CHANNEL_REAL);
|
|
|
+
|
|
|
+ compoundSealPdfListDetachedRequest.setBody(requestBody);
|
|
|
+ //****************************** 请求服务端进行签章 *********************************************
|
|
|
+ ResponseDto responseDto = paperlessClient.execute(compoundSealPdfListDetachedRequest);
|
|
|
+
|
|
|
+ //******************************解析响应结果 *********************************************
|
|
|
+ CompoundSealPdfListDetachedResponse compoundSealPdfListDetachedResponse = (CompoundSealPdfListDetachedResponse) responseDto;
|
|
|
+ ResponseHead responseHead = compoundSealPdfListDetachedResponse.getHead();
|
|
|
+ CompoundSealPdfListDetachedResponseBody responseBody = compoundSealPdfListDetachedResponse.getBody();
|
|
|
+ if (ClientConstants.CODE_SUCCESS.equals(responseHead.getCode())) {
|
|
|
+ List<PdfBean4Response> pdfBeanList = responseBody.getPdfBeans();
|
|
|
+ if (pdfBeanList != null && pdfBeanList.size() > 0) {
|
|
|
+ PdfBean4Response pdfBean4Response = pdfBeanList.get(0);
|
|
|
+ result[0] = pdfBean4Response.getPdf();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.info("【电签模块】{}", "签章响应Response:" + compoundSealPdfListDetachedResponse);
|
|
|
+ logger.info("【电签模块】{}", "签章响应code:" + responseHead.getCode());
|
|
|
+ result[0] = null;
|
|
|
+ result[1] = compoundSealPdfListDetachedResponse.toString();
|
|
|
+ result[2] = responseHead.getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.info("【电签模块】{}", "电签签章接口调用异常");
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造机构章签章策略 - 档案认证
|
|
|
+ */
|
|
|
+ private List<SealStrategy> generateSealStrategies_2(List<SealStrategyVO> strategyVoList, PdfReader reader, int typeGenerate) {
|
|
|
+ List<SealStrategy> sealStrategies = new ArrayList<>();
|
|
|
+
|
|
|
+ if (strategyVoList == null || strategyVoList.size() <= 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //构建策略
|
|
|
+ for (SealStrategyVO vo : strategyVoList) {
|
|
|
+ try {
|
|
|
+ SealStrategy sealStrategy = new SealStrategy();
|
|
|
+
|
|
|
+ // 使用图片签章
|
|
|
+ String type = BaseConstants.SEAL_TYPE_IMAGE;
|
|
|
+
|
|
|
+ String sealCode = vo.getSealCode();
|
|
|
+ String sealPassword = PwdEncryptUtil.encrypto(vo.getSealPassword());
|
|
|
+ sealStrategy.setSealInfo(type, sealCode, sealPassword);
|
|
|
+
|
|
|
+ //单笔业务流水号 非空
|
|
|
+ String serialNo = GUIDUtil.generateId();
|
|
|
+ sealStrategy.setSerialNo(serialNo);
|
|
|
+
|
|
|
+ //算法
|
|
|
+ String hashAlg = BaseConstants.HASHALG_SHA256;
|
|
|
+ sealStrategy.setHashAlg(hashAlg);
|
|
|
+ //透明度,0-1.0f,默认1.0f,不透明
|
|
|
+ String fillOpacity = "1";
|
|
|
+ sealStrategy.setFillOpacity(fillOpacity);
|
|
|
+ //是否显示,默认1 显示
|
|
|
+ String visible = "1";
|
|
|
+ sealStrategy.setVisible(visible);
|
|
|
+
|
|
|
+ if (!"authentication".equals(vo.getImageUrl())) {
|
|
|
+ String imageUrl = vo.getImageUrl();
|
|
|
+ if (StringUtils.isEmpty(imageUrl)) {
|
|
|
+ logger.info("签章图片url为null,签章人员:" + vo.getSealPerson());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //获取字节
|
|
|
+ byte[] imageData = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(imageUrl));
|
|
|
+ //对图片进行扣白底
|
|
|
+ imageData = ImageUtil.transferAlpha(imageData);
|
|
|
+
|
|
|
+ //设置大小(首先排查档案水印章,因为水印章要保持原样)
|
|
|
+ if (!vo.getImageUrl().equals("https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230911/5b42583d931664b785ebf481c37d17bc.png")) {
|
|
|
+ //个人CA签名体大小
|
|
|
+ imageData = ImageUtil.resizeImage(imageData, 480, 132);
|
|
|
+ }
|
|
|
+
|
|
|
+ //图片dpi设置
|
|
|
+ imageData = this.handleDpi(imageData);
|
|
|
+
|
|
|
+ if (imageData != null) {
|
|
|
+ //图片进行Base64编码/
|
|
|
+ String imageDataString = new String(Base64.encode(imageData), StandardCharsets.UTF_8);
|
|
|
+ sealStrategy.setSealImage(imageDataString);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //工程文件认证的 是要用透明图片
|
|
|
+ sealStrategy.setSealImage(EVisaConstant.base64String);
|
|
|
+ }
|
|
|
+
|
|
|
+ sealStrategy.setSealMiscInfo(vo.getSealPerson(), vo.getSealLocation(), vo.getSealReason());
|
|
|
+
|
|
|
+ //关键字签章
|
|
|
+ sealStrategy.setSealType(vo.getSealType());
|
|
|
+
|
|
|
+ if (vo.getSealType().equals("2")) {
|
|
|
+ //设置PDF坐标原点,签章图片定位点,默认为PDF左下角,签章图片定位为左下角
|
|
|
+ if (StringUtils.isNotEmpty(vo.getIsCenterCoordinate())) {
|
|
|
+ sealStrategy.setIsCenterCoordinate(vo.getIsCenterCoordinate());
|
|
|
+ }
|
|
|
+
|
|
|
+ //认证,设置签章位置居中
|
|
|
+ if (typeGenerate == 2) {
|
|
|
+ //居中
|
|
|
+ Rectangle page = reader.getPageSize(Integer.parseInt(vo.getPage()));
|
|
|
+ float x = (page.getLeft() + page.getRight()) / 2;
|
|
|
+ float y = (page.getTop() + page.getBottom()) / 2;
|
|
|
+ sealStrategy.setSignWithCoordinate(vo.getPage(), String.valueOf(x), String.valueOf(y));
|
|
|
+
|
|
|
+ //批量审批,设置自定义坐标位置
|
|
|
+ } else if (typeGenerate == 1) {
|
|
|
+ //重新计算,解决偏差值问题
|
|
|
+ Rectangle page = reader.getPageSize(Integer.parseInt(vo.getPage()));
|
|
|
+ float x1 = page.getWidth() / 100 * Float.parseFloat(vo.getLx()) + 3;
|
|
|
+ float y1 = page.getHeight() / 100 * Float.parseFloat(vo.getLy());
|
|
|
+ String x2 = String.valueOf(x1).substring(0, String.valueOf(x1).indexOf("."));
|
|
|
+ String y2 = String.valueOf(y1).substring(0, String.valueOf(y1).indexOf("."));
|
|
|
+ sealStrategy.setSignWithCoordinate(vo.getPage(), x2, y2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sealStrategies.add(sealStrategy);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sealStrategies;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 设置图片的dpi
|
|
|
*/
|