|
@@ -0,0 +1,175 @@
|
|
|
+package org.springblade.evisa.service.impl;
|
|
|
+
|
|
|
+import cfca.paperless.ClientConstants;
|
|
|
+import cfca.paperless.base.BaseConstants;
|
|
|
+import cfca.paperless.base.util.Base64;
|
|
|
+import cfca.paperless.base.util.GUIDUtil;
|
|
|
+import cfca.paperless.base.util.PwdEncryptUtil;
|
|
|
+import cfca.paperless.client.PaperlessClient;
|
|
|
+import cfca.paperless.dto.RequestHead;
|
|
|
+import cfca.paperless.dto.ResponseDto;
|
|
|
+import cfca.paperless.dto.ResponseHead;
|
|
|
+import cfca.paperless.dto.bean.SealCertBean;
|
|
|
+import cfca.paperless.dto.bean.SealInfoBean;
|
|
|
+import cfca.paperless.dto.request.requestbody.tx20.MakeSealRequestBody;
|
|
|
+import cfca.paperless.dto.request.tx20.MakeSealRequest;
|
|
|
+import cfca.paperless.dto.request.tx40.CompoundSealPdfListDetachedRequest;
|
|
|
+import cfca.paperless.dto.response.responsebody.tx20.MakeSealResponseBody;
|
|
|
+import cfca.paperless.dto.response.tx20.MakeSealResponse;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springblade.business.feign.TaskQueryBusinessFileClient;
|
|
|
+import org.springblade.business.vo.TaskApprovalVO;
|
|
|
+import org.springblade.common.constant.EVisaConstant;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.evisa.redissionUtil.DistributedRedisLock;
|
|
|
+import org.springblade.evisa.service.EVisaService;
|
|
|
+import org.springblade.evisa.vo.EVisaMakeSealVO;
|
|
|
+import org.springblade.evisa.vo.EVisaTaskApprovalVO;
|
|
|
+import org.springblade.manager.entity.SignPfxFile;
|
|
|
+import org.springblade.manager.feign.SignPfxClient;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class EVisaServiceImpl implements EVisaService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(EVisaServiceImpl.class);
|
|
|
+
|
|
|
+ private final SignPfxClient signPfxClient;
|
|
|
+
|
|
|
+ private final TaskQueryBusinessFileClient taskQueryBusinessFileClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void eVisa(EVisaTaskApprovalVO task) {
|
|
|
+ //todo 这里应当是配置限制参数,初版暂时写死
|
|
|
+ int batch = 20;
|
|
|
+
|
|
|
+ //首先获取当前用户的证书信息
|
|
|
+ List<SignPfxFile> userPfxList = this.signPfxClient.querySignPfxByUserIdOrContractId(AuthUtil.getUserId().toString(), "");
|
|
|
+ if(userPfxList == null || userPfxList.size() <= 0){
|
|
|
+ //没有签章,不执行电签
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据任务类型获取对应的文件信息
|
|
|
+ TaskApprovalVO taskFile = this.taskQueryBusinessFileClient.queryBusinessData(JSONObject.parseObject(JSONObject.toJSONString(task), TaskApprovalVO.class));
|
|
|
+ if(taskFile == null || taskFile.getApprovalFileList().size() <= 0){
|
|
|
+ //没有找到业务文件,取消签章
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //上锁
|
|
|
+ if(DistributedRedisLock.acquire(AuthUtil.getUserId().toString(), batch)){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签章
|
|
|
+ */
|
|
|
+ private boolean signPdf(){
|
|
|
+ StringBuffer stringbuffer = new StringBuffer();
|
|
|
+ try{
|
|
|
+ PaperlessClient paperlessClient = new PaperlessClient("host", "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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String createSeal(EVisaMakeSealVO vo) {
|
|
|
+ try{
|
|
|
+ PaperlessClient paperlessClient = new PaperlessClient("host", "port", 3000, 20000);
|
|
|
+ paperlessClient.setSSL(false);
|
|
|
+
|
|
|
+ // ------构造请求报文头------
|
|
|
+ // 请求报文头
|
|
|
+ RequestHead requestHeadBean = new RequestHead();
|
|
|
+ requestHeadBean.setTransactionNo(GUIDUtil.generateId());
|
|
|
+ requestHeadBean.setOrganizationCode(EVisaConstant.organizationCode);
|
|
|
+ requestHeadBean.setOperatorCode(EVisaConstant.operationCode);
|
|
|
+ // ------构造请求报文体------
|
|
|
+ //获取签字图片的字节数据
|
|
|
+ byte[] sealImage = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(vo.getImageUrl()));
|
|
|
+ String sealImageString = Base64.encode(sealImage, ClientConstants.CHARACTER_ENCODING);
|
|
|
+
|
|
|
+ // 构造sealCert
|
|
|
+ SealCertBean sealCertBean = new SealCertBean(vo.getCustomerType());
|
|
|
+
|
|
|
+ // PFX文件数据
|
|
|
+ // 外部传入预先生成的PFX文件数据,需要保证前面的这些信息准确无误
|
|
|
+ byte[] pfxFileData = CommonUtil.InputStreamToBytes(CommonUtil.getOSSInputStream(vo.getPfxFileUrl()));
|
|
|
+ String pkcs12String = Base64.encode(pfxFileData, ClientConstants.CHARACTER_ENCODING);
|
|
|
+
|
|
|
+ //加密证书密码
|
|
|
+ String privateKeyPassword = vo.getPfxPassword();
|
|
|
+ String pkcs12Password = PwdEncryptUtil.encrypto(privateKeyPassword);
|
|
|
+
|
|
|
+ sealCertBean.setMakeSealWithPkcs12(pkcs12String, pkcs12Password, BaseConstants.KEY_ALG_RSA , BaseConstants.KEY_ALG_LENGTH_2048);
|
|
|
+ sealCertBean.setUserInfo(vo.getUserName(), vo.getIdType(), vo.getIdNumber());
|
|
|
+
|
|
|
+ // 构造sealInfo
|
|
|
+ SealInfoBean sealInfoBean = new SealInfoBean(vo.getSealCode(), PwdEncryptUtil.encrypto(vo.getSealPassword()), vo.getSealName());
|
|
|
+
|
|
|
+ // 请求报文体
|
|
|
+ MakeSealRequestBody requestBodyBean = new MakeSealRequestBody();
|
|
|
+ requestBodyBean.setSealImage(sealImageString);
|
|
|
+ requestBodyBean.setSealImageData(sealImage);
|
|
|
+ requestBodyBean.setSealCert(sealCertBean);
|
|
|
+ requestBodyBean.setSealInfo(sealInfoBean);
|
|
|
+
|
|
|
+ // ------构造请求报文对象------
|
|
|
+ MakeSealRequest requestBean = new MakeSealRequest();
|
|
|
+ requestBean.setHead(requestHeadBean);
|
|
|
+ requestBean.setBody(requestBodyBean);
|
|
|
+ logger.info("【电签模块】{}","创建印章请求Request:"+requestBean);
|
|
|
+ // ------调用接口------
|
|
|
+ ResponseDto responseDto = paperlessClient.execute(requestBean);
|
|
|
+
|
|
|
+ // 接收响应报文对象
|
|
|
+ MakeSealResponse responseBean = (MakeSealResponse) responseDto;
|
|
|
+ logger.info("【电签模块】{}","创建印章响应Response:"+requestBean);
|
|
|
+
|
|
|
+ // 响应报文头
|
|
|
+ ResponseHead responseHeadBean = responseBean.getHead();
|
|
|
+ // 响应报文体
|
|
|
+ MakeSealResponseBody responseBodyBean = responseBean.getBody();
|
|
|
+ logger.info("【电签模块】{}", "创建印章成功==========certDn: " + responseBodyBean.getCertDn() + " ; message: " + responseHeadBean.getMessage());
|
|
|
+ //请求结果
|
|
|
+ return responseHeadBean.getCode();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|