329 lines
14 KiB
Java
329 lines
14 KiB
Java
package com.ruoyi.wisdomarbitrate.utils;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonObject;
|
|
import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
|
|
import com.ruoyi.common.enums.EsignRequestType;
|
|
import com.ruoyi.common.exception.EsignDemoException;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.EsignApplicaConfig;
|
|
import com.ruoyi.common.utils.EsignHttpHelper;
|
|
import com.ruoyi.wisdomarbitrate.domain.SealSignRecord;
|
|
|
|
import java.util.Date;
|
|
import java.util.Map;
|
|
|
|
public class SignAward {
|
|
|
|
private static String eSignHost= EsignApplicaConfig.EsignHost;
|
|
private static String eSignAppId= EsignApplicaConfig.EsignAppId;
|
|
private static String eSignAppSecret= EsignApplicaConfig.EsignAppSecret;
|
|
// public static String fileId = "95d0c307d91e4985bdb8874f6f84daa5";
|
|
public static String fileId = "a0c2ad21065f48ff8b872412c39d5d3a";
|
|
|
|
|
|
|
|
public static void main(String[] args) throws EsignDemoException {
|
|
Gson gson = new Gson();
|
|
|
|
SealSignRecord sealSignRecord = new SealSignRecord();
|
|
|
|
|
|
/* 发起签署*/
|
|
// EsignHttpResponse createByFile = createByFile(sealSignRecord);
|
|
// JsonObject createByFileJsonObject = gson.fromJson(createByFile.getBody(), JsonObject.class);
|
|
// JsonObject createByFileData = createByFileJsonObject.getAsJsonObject("data");
|
|
// String signFlowId = createByFileData.get("signFlowId").getAsString();
|
|
// System.err.println("流程id:"+signFlowId);
|
|
|
|
/* 获取文件签名印章位置*/
|
|
// EsignHttpResponse positions = getPositions(sealSignRecord);
|
|
// JsonObject positionsJsonObject = gson.fromJson(positions.getBody(), JsonObject.class);
|
|
// JsonObject positionsData = positionsJsonObject.getAsJsonObject("data");
|
|
// JsonArray keywordPositions = positionsData.get("keywordPositions").getAsJsonArray();
|
|
// System.out.println("获取文件签名印章位置:" +keywordPositions.toString());
|
|
|
|
// String signFlowId = "c9955453716344f9971d308abdc13464";
|
|
//获取合同文件签名链接
|
|
// EsignHttpResponse signUrl = signUrl(sealSignRecord);
|
|
// JsonObject signUrlJsonObject = gson.fromJson(signUrl.getBody(), JsonObject.class);
|
|
// JsonObject signUrlData = signUrlJsonObject.getAsJsonObject("data");
|
|
// String shortUrl = signUrlData.get("shortUrl").getAsString();
|
|
// String url = signUrlData.get("url").getAsString();
|
|
// System.out.println("签署短链接:" +shortUrl);
|
|
// System.out.println("签署长链接:"+url);
|
|
|
|
//获取合同文件用印链接
|
|
// EsignHttpResponse usesealUrl = usesealUrl(sealSignRecord);
|
|
// JsonObject usesealUrlJsonObject = gson.fromJson(usesealUrl.getBody(), JsonObject.class);
|
|
// JsonObject usesealUrlData = usesealUrlJsonObject.getAsJsonObject("data");
|
|
// String shortusesealUrl = usesealUrlData.get("shortUrl").getAsString();
|
|
// String sealUrl = usesealUrlData.get("url").getAsString();
|
|
// System.out.println("签署长链接:" +shortusesealUrl);
|
|
// System.out.println("签署短链接:"+sealUrl);
|
|
|
|
//查询签署流程详情
|
|
// EsignHttpResponse signFlowDetail = signFlowDetail(sealSignRecord);
|
|
// JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(),JsonObject.class);
|
|
// JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
|
|
// JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
|
|
// for (int i = 0; i < signersArray.size(); i++) {
|
|
// JsonObject signerObject = (JsonObject)signersArray.get(i);
|
|
// Integer psnsignStatus ;
|
|
// Integer orgsignStatus ;
|
|
// if(!(signerObject.get("psnSigner").toString()).equals("null")){
|
|
// JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
|
|
// if(psnSignerData!=null){
|
|
// psnsignStatus = signerObject.get("signStatus").getAsInt();
|
|
// sealSignRecord.setPsnsignStatus(psnsignStatus);
|
|
// }
|
|
// }
|
|
// if(!(signerObject.get("orgSigner").toString()).equals("null")){
|
|
// JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
|
|
// if(orgSignerData!=null){
|
|
// orgsignStatus = signerObject.get("signStatus").getAsInt();
|
|
// sealSignRecord.setOrgsignStatus(orgsignStatus);
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
|
|
// System.out.println(signFlowDetailJsonObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 查询签署流程详情
|
|
* @return
|
|
*/
|
|
public static EsignHttpResponse signFlowDetail(SealSignRecord sealSignRecord) throws EsignDemoException {
|
|
String signFlowId = sealSignRecord.getSignFlowid();
|
|
String apiaddr= "/v3/sign-flow/"+ signFlowId + "/detail";
|
|
String jsonParm = null;
|
|
//请求方法
|
|
EsignRequestType requestType = EsignRequestType.GET;
|
|
//生成签名鉴权方式的的header
|
|
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId,eSignAppSecret,jsonParm,requestType.name(),apiaddr,true);
|
|
//发起接口请求
|
|
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr,requestType , jsonParm, header,true);
|
|
}
|
|
|
|
|
|
/**
|
|
* 发起签署
|
|
* @return
|
|
* @throws EsignDemoException
|
|
*/
|
|
public static EsignHttpResponse createByFile(SealSignRecord sealSignRecord) throws EsignDemoException {
|
|
String apiaddr = "/v3/sign-flow/create-by-file";
|
|
|
|
String fileId = sealSignRecord.getFileid();
|
|
String fileName = sealSignRecord.getFilename();
|
|
|
|
String psnAccount = sealSignRecord.getPensonAccount();
|
|
String psnName = sealSignRecord.getPensonName();
|
|
|
|
String orgName = sealSignRecord.getOrgnizeName();
|
|
String orgNamePsnAccount = sealSignRecord.getOrgnizeNamePsnAccount();
|
|
String orgNamepsnName = sealSignRecord.getOrgnizeNamepsnName();
|
|
|
|
String positionPagepsn = sealSignRecord.getPositionPagepsn();
|
|
double positionXpsn = sealSignRecord.getPositionXpsn();
|
|
double positionYpsn = sealSignRecord.getPositionYpsn();
|
|
|
|
String positionPageorg = sealSignRecord.getPositionPageorg();
|
|
double positionXorg = sealSignRecord.getPositionXorg();
|
|
double positionYorg = sealSignRecord.getPositionYorg();
|
|
|
|
String jsonParm = "{\n" +
|
|
" \"docs\": [\n" +
|
|
" {\n" +
|
|
" \"fileId\": \"" + fileId + "\",\n" +
|
|
" \"fileName\": \"" + fileName + "\"\n" +
|
|
|
|
" }\n" +
|
|
" ],\n" +
|
|
" \"signFlowConfig\": {\n" +
|
|
" \"signFlowTitle\": \"测试合同\",\n" +
|
|
" \"autoStart\": true,\n" +
|
|
" \"authConfig\": {\n" +
|
|
" \"willingnessAuthModes\": [\n" +
|
|
" \"CODE_SMS\"\n" +
|
|
" ],\n" +
|
|
" \"psnAvailableAuthModes\": [\n" +
|
|
" \"PSN_MOBILE3\"\n" +
|
|
" ],\n" +
|
|
" \"orgAvailableAuthModes\": [\n" +
|
|
" \"ORG_LEGALREP\"\n" +
|
|
" ]\n" +
|
|
" },\n" +
|
|
" \"autoFinish\": true\n" +
|
|
" },\n" +
|
|
|
|
" \"signers\": [\n" +
|
|
|
|
" {\n" +
|
|
|
|
" \"psnSignerInfo\": {\n" +
|
|
" \"psnAccount\": \"" + psnAccount + "\",\n" +
|
|
|
|
" \"psnInfo\": {\n" +
|
|
" \"psnName\": \"" + psnName + "\"\n" +
|
|
" }\n" +
|
|
|
|
" },\n" +
|
|
" \"signFields\": [\n" +
|
|
" {\n" +
|
|
|
|
" \"fileId\": \"" + fileId + "\",\n" +
|
|
|
|
" \"normalSignFieldConfig\": {\n" +
|
|
" \"autoSign\": false,\n" +
|
|
" \"freeMode\": false,\n" +
|
|
" \"movableSignField\": false,\n" +
|
|
" \"signFieldPosition\": {\n" +
|
|
" \"positionPage\": \"" + positionPagepsn + "\",\n" +
|
|
" \"positionX\": " + positionXpsn + ",\n" +
|
|
" \"positionY\": " + positionYpsn + "\n" +
|
|
" },\n" +
|
|
" \"signFieldStyle\": 1\n" +
|
|
" },\n" +
|
|
" \"signFieldType\": 0\n" +
|
|
" }\n" +
|
|
" ],\n" +
|
|
" \"signerType\": 0\n" +
|
|
" },\n" +
|
|
|
|
|
|
" {\n" +
|
|
" \"orgSignerInfo\": {\n" +
|
|
" \"orgName\": \"" + orgName + "\",\n" +
|
|
" \"transactorInfo\": {\n" +
|
|
" \"psnAccount\": \"" + orgNamePsnAccount + "\",\n" +
|
|
|
|
" \"psnInfo\": {\n" +
|
|
|
|
" \"psnName\": \"" + orgNamepsnName + "\"\n" +
|
|
" }\n" +
|
|
|
|
" }\n" +
|
|
" },\n" +
|
|
|
|
" \"signFields\": [\n" +
|
|
" {\n" +
|
|
" \"fileId\": \"" + fileId + "\",\n" +
|
|
|
|
" \"normalSignFieldConfig\": {\n" +
|
|
" \"autoSign\": false,\n" +
|
|
" \"freeMode\": false,\n" +
|
|
|
|
" \"signFieldPosition\": {\n" +
|
|
|
|
" \"positionPage\": \"" + positionPageorg + "\",\n" +
|
|
" \"positionX\": " + positionXorg + ",\n" +
|
|
" \"positionY\": " + positionYorg + "\n" +
|
|
" },\n" +
|
|
" \"signFieldStyle\": 1\n" +
|
|
" },\n" +
|
|
" \"signFieldType\": 0\n" +
|
|
" }\n" +
|
|
" ],\n" +
|
|
" \"signerType\": 1\n" +
|
|
" }\n" +
|
|
|
|
" ]\n" +
|
|
"}";
|
|
|
|
//请求方法
|
|
EsignRequestType requestType = EsignRequestType.POST;
|
|
//生成请求签名鉴权方式的Header
|
|
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
|
|
//发起接口请求
|
|
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
|
|
}
|
|
|
|
/**
|
|
* 获取合同文件签名链接
|
|
* @return
|
|
* @throws EsignDemoException
|
|
*/
|
|
public static EsignHttpResponse signUrl(SealSignRecord sealSignRecord) throws EsignDemoException {
|
|
|
|
String signFlowId = sealSignRecord.getSignFlowid();
|
|
String psnAccount = sealSignRecord.getPensonAccount();
|
|
|
|
String apiaddr = "/v3/sign-flow/" + signFlowId + "/sign-url";
|
|
String jsonParm = "{\n" +
|
|
" \"operator\": {\n" +
|
|
" \"psnAccount\": \"" + psnAccount + "\"\n" +
|
|
" }\n" +
|
|
"}";
|
|
//请求方法
|
|
EsignRequestType requestType = EsignRequestType.POST;
|
|
//生成请求签名鉴权方式的Header
|
|
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
|
|
//发起接口请求
|
|
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
|
|
}
|
|
|
|
/**
|
|
* 获取合同文件用印链接
|
|
* @return
|
|
* @throws EsignDemoException
|
|
*/
|
|
public static EsignHttpResponse usesealUrl(SealSignRecord sealSignRecord) throws EsignDemoException {
|
|
String signFlowId = sealSignRecord.getSignFlowid();
|
|
String apiaddr = "/v3/sign-flow/" + signFlowId + "/sign-url";
|
|
|
|
String psnAccount = sealSignRecord.getOrgnizeNamePsnAccount();
|
|
String orgName = sealSignRecord.getOrgnizeName();
|
|
|
|
String jsonParm = "{\n" +
|
|
" \"operator\": {\n" +
|
|
|
|
" \"psnAccount\": \"" + psnAccount + "\"\n" +
|
|
" },\n" +
|
|
" \"organization\": {\n" +
|
|
" \"orgName\": \"" + orgName + "\"\n" +
|
|
|
|
" }\n" +
|
|
"}";
|
|
//请求方法
|
|
EsignRequestType requestType = EsignRequestType.POST;
|
|
//生成请求签名鉴权方式的Header
|
|
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
|
|
//发起接口请求
|
|
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
|
|
}
|
|
|
|
/**
|
|
* 获取文件签名印章位置
|
|
* @return
|
|
* @throws EsignDemoException
|
|
*/
|
|
public static EsignHttpResponse getPositions(SealSignRecord sealSignRecord) throws EsignDemoException {
|
|
String fileId = sealSignRecord.getFileid();
|
|
String apiaddr = "/v3/files/" + fileId + "/keyword-positions";
|
|
String jsonParm = "{\n" +
|
|
" \"keywords\": [\n" +
|
|
" \"仲裁员:\",\n" +
|
|
" \"(仲裁委员会盖章)\"\n" +
|
|
" ]\n" +
|
|
"}";
|
|
//请求方法
|
|
EsignRequestType requestType = EsignRequestType.POST;
|
|
//生成请求签名鉴权方式的Header
|
|
Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
|
|
//发起接口请求
|
|
return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|