|
@@ -13,21 +13,28 @@ import cfca.paperless.dto.ResponseHead;
|
|
|
import cfca.paperless.dto.bean.*;
|
|
|
import cfca.paperless.dto.request.requestbody.tx20.MakeSealRequestBody;
|
|
|
import cfca.paperless.dto.request.requestbody.tx40.CompoundSealPdfListRequestBody;
|
|
|
+import cfca.paperless.dto.request.requestbody.tx40.VerifyPdfSealRequestBody;
|
|
|
import cfca.paperless.dto.request.tx20.MakeSealRequest;
|
|
|
import cfca.paperless.dto.request.tx40.CompoundSealPdfListDetachedRequest;
|
|
|
+import cfca.paperless.dto.request.tx40.VerifyPdfSealRequest;
|
|
|
import cfca.paperless.dto.response.responsebody.tx20.MakeSealResponseBody;
|
|
|
import cfca.paperless.dto.response.responsebody.tx40.CompoundSealPdfListDetachedResponseBody;
|
|
|
+import cfca.paperless.dto.response.responsebody.tx40.VerifyPdfSealResponseBody;
|
|
|
import cfca.paperless.dto.response.tx20.MakeSealResponse;
|
|
|
import cfca.paperless.dto.response.tx40.CompoundSealPdfListDetachedResponse;
|
|
|
+import cfca.paperless.dto.response.tx40.VerifyPdfSealResponse;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springblade.business.feign.TaskClient;
|
|
|
import org.springblade.business.vo.TaskApprovalVO;
|
|
|
import org.springblade.common.constant.EVisaConstant;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.evisa.redissionUtil.DistributedRedisLock;
|
|
@@ -39,7 +46,9 @@ import org.springblade.evisa.vo.SealStrategyVO;
|
|
|
import org.springblade.manager.entity.SignPfxFile;
|
|
|
import org.springblade.manager.feign.SignPfxClient;
|
|
|
import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.*;
|
|
|
import javax.imageio.metadata.IIOInvalidTreeException;
|
|
@@ -50,6 +59,7 @@ import java.awt.image.BufferedImage;
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
@@ -65,6 +75,12 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
|
|
|
private static final double INCH_2_CM = 2.54d;
|
|
|
|
|
|
+ private static final String ERROR = "error";
|
|
|
+
|
|
|
+ private static final String NOT_PFX_OR_FILE = "notPfxOrFile";
|
|
|
+
|
|
|
+ private static final String SUCCESS = "success";
|
|
|
+
|
|
|
private static final Logger logger = LoggerFactory.getLogger(EVisaServiceImpl.class);
|
|
|
|
|
|
private final SignPfxClient signPfxClient;
|
|
@@ -76,37 +92,58 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
@Override
|
|
|
public String certification(String pdfUrl, String fileName, String contractId) {
|
|
|
try{
|
|
|
- //准备签章策略
|
|
|
- List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
//根据当前合同段获取相关的证书
|
|
|
List<SignPfxFile> pfxFiles = this.signPfxClient.querySignPfxByUserIdOrContractId("", contractId);
|
|
|
if(pfxFiles == null || pfxFiles.size() <= 0){
|
|
|
- return "error";
|
|
|
+ return NOT_PFX_OR_FILE;
|
|
|
}
|
|
|
- SealStrategyVO vo = new SealStrategyVO();
|
|
|
- vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + AuthUtil.getUserId().toString().substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
- vo.setSealPassword(AuthUtil.getUserId().toString().substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
- vo.setSealPerson(AuthUtil.getUserAccount());
|
|
|
- //使用默认写死的透明图片
|
|
|
- vo.setImageUrl("authentication");
|
|
|
- //使用坐标定位 ,坐标固定
|
|
|
- vo.setSealType("2");
|
|
|
- vo.setLx("100");
|
|
|
- vo.setLy("100");
|
|
|
- vo.setPage("1");
|
|
|
- sealStrategyVOS.add(vo);
|
|
|
+ //找到合同章
|
|
|
+ SignPfxFile contractPfx = null;
|
|
|
+ for(SignPfxFile pfxFile : pfxFiles){
|
|
|
+ if("2".equals(pfxFile.getPfxType())){
|
|
|
+ //找到当前合同段的合同章类型
|
|
|
+ contractPfx = pfxFile;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //没有找到合同章,直接返回
|
|
|
+ if(contractPfx == null){
|
|
|
+ return NOT_PFX_OR_FILE;
|
|
|
+ }
|
|
|
+
|
|
|
+ //准备签章策略
|
|
|
+ List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
|
|
|
+ //获取需要认证的文件
|
|
|
+ InputStream pdfInputStream = CommonUtil.getOSSInputStream(pdfUrl);
|
|
|
+ //获取这份文件的页数并设置签章策略
|
|
|
+ //获取PDF文件
|
|
|
+ PDDocument document = PDDocument.load(pdfInputStream);
|
|
|
+ int page = document.getPages().getCount();
|
|
|
+ for(int i = 0; i < page; i ++){
|
|
|
+ SealStrategyVO vo = new SealStrategyVO();
|
|
|
+ vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + contractPfx.getCertificatePassword());
|
|
|
+ vo.setSealPassword(contractPfx.getCertificatePassword());
|
|
|
+ vo.setSealPerson(contractPfx.getCertificateUserName());
|
|
|
+ //使用默认写死的透明图片
|
|
|
+ vo.setImageUrl("authentication");
|
|
|
+ //使用坐标定位 ,坐标固定
|
|
|
+ vo.setSealType("2");
|
|
|
+ vo.setLx("100");
|
|
|
+ vo.setLy("100");
|
|
|
+ vo.setPage(( i + 1) + "");
|
|
|
+ sealStrategyVOS.add(vo);
|
|
|
+ }
|
|
|
SealPdfVO pdfVO = new SealPdfVO();
|
|
|
pdfVO.setStrategyVoList(sealStrategyVOS);
|
|
|
|
|
|
- //获取认证文件
|
|
|
+ //获取字节
|
|
|
byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pdfUrl));
|
|
|
//兼容大文件签章
|
|
|
Object[] result;
|
|
|
//大于50M的单个文件采用大文件签章处理
|
|
|
if(fileByte.length > 52428800){
|
|
|
result = null;
|
|
|
-
|
|
|
} else {
|
|
|
//普通文件签章
|
|
|
result = this.signPdf(pdfVO, fileByte);
|
|
@@ -114,12 +151,13 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
if(result != null){
|
|
|
if(result[0] != null){
|
|
|
byte[] newPdfData = (byte[])result[0];
|
|
|
- //重新上传覆盖
|
|
|
- BladeFile bladeFile = this.newIOSSClient.updateFile(newPdfData, pdfUrl.substring(pdfUrl.lastIndexOf("/") + 1, pdfUrl.lastIndexOf(".")));
|
|
|
+ MultipartFile files = new MockMultipartFile("file", SnowFlakeUtil.getId() + ".pdf", "text/plain", IOUtils.toByteArray(new ByteArrayInputStream(newPdfData)));
|
|
|
+ //重新上传
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFileByInputStream(files);
|
|
|
if(bladeFile != null){
|
|
|
- return "success" + "@@@@" + bladeFile.getLink();
|
|
|
+ return SUCCESS + "@@@@" + bladeFile.getLink();
|
|
|
} else {
|
|
|
- return "error";
|
|
|
+ return ERROR;
|
|
|
}
|
|
|
} else {
|
|
|
String s = result[1].toString();
|
|
@@ -137,10 +175,11 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Override
|
|
|
public String eVisa(EVisaTaskApprovalVO task) {
|
|
|
+ if(true){
|
|
|
+ return SUCCESS;
|
|
|
+ }
|
|
|
//todo 这里应当是配置限制参数,初版暂时写死
|
|
|
int batch = 20;
|
|
|
|
|
@@ -148,26 +187,67 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
List<SignPfxFile> userPfxList = this.signPfxClient.querySignPfxByUserIdOrContractId(AuthUtil.getUserId().toString(), "");
|
|
|
if(userPfxList == null || userPfxList.size() <= 0){
|
|
|
//没有签章,不执行电签
|
|
|
- return "error";
|
|
|
+ return NOT_PFX_OR_FILE;
|
|
|
}
|
|
|
|
|
|
//根据任务类型获取对应的文件信息
|
|
|
TaskApprovalVO taskFile = this.taskClient.queryBusinessData(JSONObject.parseObject(JSONObject.toJSONString(task), TaskApprovalVO.class));
|
|
|
if(taskFile == null || taskFile.getApprovalFileList().size() <= 0){
|
|
|
//没有找到业务文件,取消签章
|
|
|
- return "error";
|
|
|
+ return NOT_PFX_OR_FILE;
|
|
|
}
|
|
|
|
|
|
//上锁
|
|
|
if(DistributedRedisLock.acquire(AuthUtil.getUserId().toString(), batch)){
|
|
|
+ try{
|
|
|
+ //获取需要签章的数据
|
|
|
+ List<TaskApprovalVO.ApprovalFile> files = taskFile.getApprovalFileList();
|
|
|
+ for(TaskApprovalVO.ApprovalFile file : files){
|
|
|
+ //获取PDF文件
|
|
|
+ PDDocument document = PDDocument.load(CommonUtil.getOSSInputStream(file.getFileUrl()));
|
|
|
+ int page = document.getPages().getCount();
|
|
|
+
|
|
|
+ //准备签章策略
|
|
|
+ List<SealStrategyVO> sealStrategyVOS = new ArrayList<>();
|
|
|
+ for(int i = 0; i <page; i ++){
|
|
|
+ //设置签章策略
|
|
|
+ SealStrategyVO vo = new SealStrategyVO();
|
|
|
+ vo.setSealCode(EVisaConstant.SIGN_SEAL_CODE + AuthUtil.getUserId());
|
|
|
+ vo.setSealPassword(AuthUtil.getUserId().toString().substring(0, EVisaConstant.USER_ID_SUB));
|
|
|
+ vo.setSealPerson(AuthUtil.getNickName());
|
|
|
+ //设置签字文件
|
|
|
+ vo.setImageUrl(userPfxList.get(0).getCertificateFileUrl());
|
|
|
+ vo.setSealType("3");
|
|
|
+
|
|
|
+ //todo ====================== 暂时缺少关键信息 =====================
|
|
|
+ //todo ====================== 暂时缺少关键信息 =====================
|
|
|
+
|
|
|
+ //设置页
|
|
|
+ vo.setPage(( i + 1) + "");
|
|
|
+ sealStrategyVOS.add(vo);
|
|
|
+ }
|
|
|
+ SealPdfVO pdfVO = new SealPdfVO();
|
|
|
+ pdfVO.setStrategyVoList(sealStrategyVOS);
|
|
|
|
|
|
+ //获取字节
|
|
|
+ byte[] fileByte = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(file.getFileUrl()));
|
|
|
+ //执行电签
|
|
|
+ Object[] result = this.signPdf(pdfVO, fileByte);
|
|
|
+ if(result == null){
|
|
|
+ return ERROR;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return ERROR;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return "success";
|
|
|
+ return SUCCESS;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 签章(坐标方式)
|
|
|
+ * 签章
|
|
|
*/
|
|
|
private Object[] signPdf(SealPdfVO pdfVO, byte[] fileByte){
|
|
|
Object[] result = new Object[2];
|
|
@@ -182,11 +262,11 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
String transactionNo = GUIDUtil.generateId();
|
|
|
//机构编码非空
|
|
|
String organizationCode = EVisaConstant.organizationCode;
|
|
|
-
|
|
|
//操作员编码 可为空(企业类型不能为空)
|
|
|
String operatorCode = EVisaConstant.operationCode;
|
|
|
//渠道编码 可为空
|
|
|
String channelCode = "";
|
|
|
+
|
|
|
//设置属性
|
|
|
requestHead.setBasicInfo(transactionNo, organizationCode,operatorCode,channelCode);
|
|
|
|
|
@@ -231,7 +311,7 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
if(ClientConstants.CODE_SUCCESS.equals(responseHead.getCode())){
|
|
|
List<PdfBean4Response> pdfBeanList = responseBody.getPdfBeans();
|
|
|
if(pdfBeanList!=null && pdfBeanList.size()>0){
|
|
|
- PdfBean4Response pdfBean4Response =pdfBeanList.get(0);
|
|
|
+ PdfBean4Response pdfBean4Response = pdfBeanList.get(0);
|
|
|
result[0] = pdfBean4Response.getPdf();
|
|
|
}
|
|
|
}else{
|
|
@@ -394,41 +474,6 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
metadata.mergeTree("javax_imageio_1.0", root);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 签章(线程方式)
|
|
|
- */
|
|
|
- private boolean signPdf(){
|
|
|
- StringBuffer stringbuffer = new StringBuffer();
|
|
|
- try{
|
|
|
- PaperlessClient paperlessClient = new PaperlessClient(SIGN_HOST, SIGN_PORT, 3000, 20000);
|
|
|
-
|
|
|
- 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);
|
|
|
- //*****************************************************************************
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 创建印模
|
|
|
*/
|
|
@@ -501,4 +546,65 @@ public class EVisaServiceImpl implements EVisaService {
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CertBean> checkSeal(String pdfUrl) {
|
|
|
+ try{
|
|
|
+ PaperlessClient paperlessClient = new PaperlessClient(SIGN_HOST, SIGN_PORT, 300000, 1800000);
|
|
|
+ paperlessClient.setSSL(false);
|
|
|
+
|
|
|
+ /*==================================================================================*/
|
|
|
+ //构造请求对象
|
|
|
+ VerifyPdfSealRequest verifyPdfSealRequest = new VerifyPdfSealRequest();
|
|
|
+ RequestHead requestHead = new RequestHead();
|
|
|
+ //业务流水号 非空
|
|
|
+ String transactionNo = GUIDUtil.generateId();
|
|
|
+ //机构编码非空
|
|
|
+ String organizationCode = EVisaConstant.organizationCode;
|
|
|
+ //操作员编码 可为空
|
|
|
+ String operatorCode = EVisaConstant.operationCode;
|
|
|
+ //渠道编码 可为空
|
|
|
+ String channelCode = EVisaConstant.channelCode;
|
|
|
+ //设置属性
|
|
|
+ requestHead.setBasicInfo(transactionNo, organizationCode,operatorCode,channelCode);
|
|
|
+
|
|
|
+ verifyPdfSealRequest.setHead(requestHead);
|
|
|
+ /*==================================================================================*/
|
|
|
+ VerifyPdfSealRequestBody requestBody = new VerifyPdfSealRequestBody();
|
|
|
+
|
|
|
+ byte[] pdfData = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(pdfUrl));
|
|
|
+ // 数据源类型 1 pdf文件路径 2 pdf文件字节流
|
|
|
+ requestBody.setInputType(BaseConstants.INPUT_TYPE_FILEDATA);
|
|
|
+ requestBody.setPdfData(pdfData);
|
|
|
+
|
|
|
+ /*验证类型
|
|
|
+ * 验证项包括以下4项:①验证印章的签名②验证签章时间点证书是否有效③验证书链④验CRL
|
|
|
+ sealVerifyType=1时,验证前3项
|
|
|
+ sealVerifyType=2时,验证全部4项
|
|
|
+ */
|
|
|
+ String sealVerifyType = BaseConstants.SEAL_VERIFY_TYPE_1;
|
|
|
+ requestBody.setSealVerifyType(sealVerifyType);
|
|
|
+
|
|
|
+ verifyPdfSealRequest.setBody(requestBody);
|
|
|
+
|
|
|
+ /*==================================================================================*/
|
|
|
+ ResponseDto responseDto = paperlessClient.execute(verifyPdfSealRequest);
|
|
|
+ /*==================================================================================*/
|
|
|
+
|
|
|
+ VerifyPdfSealResponse verifyPdfSealResponse = (VerifyPdfSealResponse)responseDto;
|
|
|
+
|
|
|
+ ResponseHead responseHead = verifyPdfSealResponse.getHead();
|
|
|
+ VerifyPdfSealResponseBody responseBody = verifyPdfSealResponse.getBody();
|
|
|
+
|
|
|
+ if(ClientConstants.CODE_SUCCESS.equals(responseHead.getCode())){
|
|
|
+ return responseBody.getCertBeans();
|
|
|
+ } else {
|
|
|
+ logger.info("【电签模块】{}","验签接口响应code:" + responseHead.getCode());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|