|
|
@@ -8,8 +8,15 @@ import com.tencentcloudapi.common.profile.ClientProfile;
|
|
|
import com.tencentcloudapi.common.profile.HttpProfile;
|
|
|
import com.tencentcloudapi.essbasic.v20210526.EssbasicClient;
|
|
|
import com.tencentcloudapi.essbasic.v20210526.models.*;
|
|
|
+import com.tencentcloudapi.tke.v20180525.models.Switch;
|
|
|
+import com.tencentcloudapi.tsf.v20180326.models.TerminateTaskFlowBatchRequest;
|
|
|
+import common.YosException;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static restcontroller.webmanage.sale.contracttask.WeChatByTemplate.BuildFormField;
|
|
|
import static restcontroller.webmanage.sale.contracttask.WeChatConfig.*;
|
|
|
|
|
|
/**
|
|
|
@@ -20,7 +27,7 @@ public class WeChatContractUtil {
|
|
|
Credential cred;
|
|
|
HttpProfile httpProfile;
|
|
|
ClientProfile clientProfile;
|
|
|
- EssbasicClient client;
|
|
|
+ static EssbasicClient client;
|
|
|
|
|
|
public WeChatContractUtil() {
|
|
|
this.cred = new Credential(WeChatConfig.SecretId, WeChatConfig.SecretKey);
|
|
|
@@ -31,11 +38,31 @@ public class WeChatContractUtil {
|
|
|
this.client = new EssbasicClient(cred, "", clientProfile);
|
|
|
}
|
|
|
|
|
|
- public Agent getAgent(String ProxyOperatorOpenId) {
|
|
|
+ public static EssbasicClient initClient() {
|
|
|
+ if (client != null) {
|
|
|
+ return client;
|
|
|
+ }
|
|
|
+ // 实例化一个认证对象,入参需要传入腾讯云账户SecretId,SecretKey,此处还需注意密钥对的保密
|
|
|
+ // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
|
|
+ Credential cred = new Credential(WeChatConfig.SecretId, WeChatConfig.SecretKey);
|
|
|
+ // 实例化一个http选项,可选的,没有特殊需求可以跳过
|
|
|
+ HttpProfile httpProfile = new HttpProfile();
|
|
|
+ httpProfile.setEndpoint(WeChatConfig.EndPoint);
|
|
|
+ // 实例化一个client选项,可选的,没有特殊需求可以跳过
|
|
|
+ ClientProfile clientProfile = new ClientProfile();
|
|
|
+ clientProfile.setHttpProfile(httpProfile);
|
|
|
+ // 实例化要请求产品的client对象,clientProfile是可选的
|
|
|
+ client = new EssbasicClient(cred, "", clientProfile);
|
|
|
+ return client;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Agent setAgent(String ProxyOperatorOpenId) {
|
|
|
// 构建 Agent 对象
|
|
|
Agent agent = new Agent();
|
|
|
agent.setAppId(WeChatConfig.AppId);
|
|
|
+ agent.setProxyAppId(WeChatConfig.ProxyAppId);
|
|
|
agent.setProxyOrganizationOpenId(ProxyOrganizationOpenId);
|
|
|
+
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
userInfo.setOpenId(ProxyOperatorOpenId);
|
|
|
agent.setProxyOperator(userInfo);
|
|
|
@@ -44,6 +71,7 @@ public class WeChatContractUtil {
|
|
|
|
|
|
//生成腾讯云电子签控制台登录URL
|
|
|
public String getUserConsoleUrl(String name, String phonenumber) throws TencentCloudSDKException {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
//根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
|
|
|
String proxyOperatorOpenId = DigestUtils.sha256Hex(name + phonenumber);
|
|
|
|
|
|
@@ -69,6 +97,7 @@ public class WeChatContractUtil {
|
|
|
|
|
|
//查询模板列表
|
|
|
public DescribeTemplatesResponse getTemplateList(String proxyOperatorOpenId) throws TencentCloudSDKException {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
//根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
|
|
|
DescribeTemplatesRequest req = new DescribeTemplatesRequest();
|
|
|
// --- 开始构建图片中的 JSON 数据 ---
|
|
|
@@ -77,7 +106,7 @@ public class WeChatContractUtil {
|
|
|
// 设置 QueryAllComponents: true
|
|
|
req.setQueryAllComponents(true);
|
|
|
// 将 Agent 设置到请求中
|
|
|
- req.setAgent(getAgent(proxyOperatorOpenId));
|
|
|
+ req.setAgent(setAgent(proxyOperatorOpenId));
|
|
|
// --- JSON 构建结束 ---
|
|
|
// 通过client对象调用对应接口
|
|
|
DescribeTemplatesResponse resp = client.DescribeTemplates(req);
|
|
|
@@ -85,6 +114,7 @@ public class WeChatContractUtil {
|
|
|
}
|
|
|
|
|
|
public DescribeTemplatesResponse getTemplateDetail(String proxyOperatorOpenId, String TemplateId) throws TencentCloudSDKException {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
//根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
|
|
|
DescribeTemplatesRequest req = new DescribeTemplatesRequest();
|
|
|
req.setTemplateId(TemplateId);
|
|
|
@@ -94,19 +124,294 @@ public class WeChatContractUtil {
|
|
|
// 设置 QueryAllComponents: true
|
|
|
req.setQueryAllComponents(true);
|
|
|
// 将 Agent 设置到请求中
|
|
|
- req.setAgent(getAgent(proxyOperatorOpenId));
|
|
|
+ req.setAgent(setAgent(proxyOperatorOpenId));
|
|
|
// --- JSON 构建结束 ---
|
|
|
// 通过client对象调用对应接口
|
|
|
DescribeTemplatesResponse resp = client.DescribeTemplates(req);
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ public static DescribeTemplatesResponse describeTemplates(Agent agent, String TemplateId) {
|
|
|
+ try {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ DescribeTemplatesRequest req = new DescribeTemplatesRequest();
|
|
|
+ req.setAgent(agent);
|
|
|
+ req.setTemplateId(TemplateId);
|
|
|
+ // 返回的resp是一个DescribeTemplatesResponse的实例,与请求对象对应
|
|
|
+ return client.DescribeTemplates(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置FlowInfo
|
|
|
+ *
|
|
|
+ * @param TemplateId 模板唯一标识
|
|
|
+ * @param FlowName 签署流程名称
|
|
|
+ * @param flowApproverInfos 签署流程签约方列表
|
|
|
+ * @return FlowInfo
|
|
|
+ */
|
|
|
+ public static FlowInfo fillFlowInfo(String TemplateId, String FlowName, FlowApproverInfo[] flowApproverInfos) {
|
|
|
+ FlowInfo flowInfo = new FlowInfo();
|
|
|
+ flowInfo.setTemplateId(TemplateId);
|
|
|
+ flowInfo.setFlowName(FlowName);
|
|
|
+ flowInfo.setFlowApprovers(flowApproverInfos);
|
|
|
+ flowInfo.setFlowType("合同");
|
|
|
+ return flowInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static CreateSignUrlsResponse createSignUrls(String[] flowIds, Agent agent) {
|
|
|
+ try {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ CreateSignUrlsRequest req = new CreateSignUrlsRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowIds(flowIds);
|
|
|
+
|
|
|
+ // 返回的resp是一个CreateSignUrlsResponse的实例,与请求对象对应
|
|
|
+ return client.CreateSignUrls(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static CreateFlowsByTemplatesResponse createFlowsByTemplates(Agent agent, FlowInfo[] flowInfos) {
|
|
|
+ try {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ CreateFlowsByTemplatesRequest req = new CreateFlowsByTemplatesRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowInfos(flowInfos);
|
|
|
+
|
|
|
+ // 返回的resp是一个CreateFlowsByTemplatesResponse的实例,与请求对象对应
|
|
|
+ return client.CreateFlowsByTemplates(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DescribeResourceUrlsByFlowsResponse describeResourceUrlsByFlows(Agent agent, String[] flowIds) {
|
|
|
+ try {
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ DescribeResourceUrlsByFlowsRequest req = new DescribeResourceUrlsByFlowsRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowIds(flowIds);
|
|
|
+
|
|
|
+ // 返回的resp是一个DescribeResourceUrlsByFlowsResponse的实例,与请求对象对应
|
|
|
+ return client.DescribeResourceUrlsByFlows(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String describeFileUrls(String flowId) {
|
|
|
+
|
|
|
+ // 设置agent参数
|
|
|
+ Agent agent = new Agent();
|
|
|
+ agent.setAppId(WeChatConfig.AppId);
|
|
|
+ agent.setProxyAppId(WeChatConfig.ProxyAppId);
|
|
|
+ agent.setProxyOrganizationOpenId(WeChatConfig.ProxyOrganizationOpenId);
|
|
|
+ UserInfo proxyOperator = new UserInfo();
|
|
|
+ proxyOperator.setOpenId(SuperProxyOperatorOpenId);
|
|
|
+ agent.setProxyOperator(proxyOperator);
|
|
|
+
|
|
|
+ String[] flowIds = new String[1];
|
|
|
+ flowIds[0] = flowId;
|
|
|
+ DescribeResourceUrlsByFlowsResponse urlResp =
|
|
|
+ describeResourceUrlsByFlows(agent, flowIds);
|
|
|
+
|
|
|
+ assert urlResp != null;
|
|
|
+ return urlResp.getFlowResourceUrlInfos()[0].getResourceUrlInfos()[0].getUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过文件base64直接发起签署流程
|
|
|
+ *
|
|
|
+ * @param flowName 签署流程名称
|
|
|
+ * @param templateId 模板唯一标识
|
|
|
+ * @return Map<String, String [ ]>
|
|
|
+ */
|
|
|
+ public static Map<String, String[]> createFlowByTemplateDirectly(String flowName,
|
|
|
+ String templateId,
|
|
|
+ FlowApproverInfo[] flowApproverInfos) {
|
|
|
+ Map<String, String[]> resp = new HashMap<>();
|
|
|
+ // 设置agent参数
|
|
|
+ Agent agent = setAgent(SuperProxyOperatorOpenId);
|
|
|
+ // 创建签署流程
|
|
|
+ // 签署数量
|
|
|
+ int count = WeChatConfig.COUNT;
|
|
|
+ FlowInfo[] FlowInfos = new FlowInfo[count];
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ FlowInfos[i] = fillFlowInfo(templateId, flowName, flowApproverInfos);
|
|
|
+ // 构建内容控件填充结构(根据自己需求使用)
|
|
|
+ FlowInfos[i].setFormFields(new FormField[]{BuildFormField("htbh", "123456")});
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发起签署
|
|
|
+ CreateFlowsByTemplatesResponse flowResponse = createFlowsByTemplates(agent, FlowInfos);
|
|
|
+ assert flowResponse != null;
|
|
|
+ String[] FlowIds = flowResponse.getFlowIds();
|
|
|
+ resp.put("FlowIds", FlowIds);
|
|
|
+
|
|
|
+ // 获取签署链接
|
|
|
+ CreateSignUrlsResponse createSignUrlsRes = createSignUrls(FlowIds, agent);
|
|
|
+ assert createSignUrlsRes != null;
|
|
|
+ if (createSignUrlsRes.getSignUrlInfos().length != 0) {
|
|
|
+ String[] Urls = new String[count];
|
|
|
+ for (int i = 0; i < count; i++) {
|
|
|
+ Urls[i] = createSignUrlsRes.getSignUrlInfos()[i].getSignUrl();
|
|
|
+ }
|
|
|
+ resp.put("Urls", Urls);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ChannelCancelFlowResponse channelCancelFlow(Agent agent, String flowId, String cancelMessage,
|
|
|
+ Long cancelMessageFormat) {
|
|
|
+ try {
|
|
|
+ // 实例化一个client
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ ChannelCancelFlowRequest req = new ChannelCancelFlowRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowId(flowId);
|
|
|
+
|
|
|
+ req.setCancelMessage(cancelMessage);
|
|
|
+
|
|
|
+ req.setCancelMessageFormat(cancelMessageFormat);
|
|
|
+
|
|
|
+ // 返回的resp是一个ChannelCancelFlowResponse的实例,与请求对象对应
|
|
|
+ return client.ChannelCancelFlow(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static ChannelBatchCancelFlowsResponse channelBatchCancelFlows(String[] flowIds, Agent agent) {
|
|
|
+ try {
|
|
|
+ // 实例化一个client
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ ChannelBatchCancelFlowsRequest req = new ChannelBatchCancelFlowsRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowIds(flowIds);
|
|
|
+
|
|
|
+ // 返回的resp是一个ChannelBatchCancelFlowsResponse的实例,与请求对象对应
|
|
|
+ return client.ChannelBatchCancelFlows(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DescribeFlowDetailInfoResponse describeFlowDetailInfo(Agent agent, String[] flowIds) {
|
|
|
+ try {
|
|
|
+ // 实例化一个client
|
|
|
+ EssbasicClient client = initClient();
|
|
|
+ // 实例化一个请求对象,每个接口都会对应一个request对象
|
|
|
+ DescribeFlowDetailInfoRequest req = new DescribeFlowDetailInfoRequest();
|
|
|
+
|
|
|
+ req.setAgent(agent);
|
|
|
+
|
|
|
+ req.setFlowIds(flowIds);
|
|
|
+
|
|
|
+ // 返回的resp是一个DescribeFlowDetailInfoResponse的实例,与请求对象对应
|
|
|
+ return client.DescribeFlowDetailInfo(req);
|
|
|
+ } catch (TencentCloudSDKException e) {
|
|
|
+ System.out.println(e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getFlowStatus(String flowStatus) {
|
|
|
+
|
|
|
+ switch (flowStatus) {
|
|
|
+ case "INIT":
|
|
|
+ return "合同创建";
|
|
|
+ case "PART":
|
|
|
+ return "合同签署中";
|
|
|
+ case "ALL":
|
|
|
+ return "合同签署完成 ";
|
|
|
+ case "REJECT":
|
|
|
+ return "合同拒签";
|
|
|
+ case "CANCEL":
|
|
|
+ return "合同撤回";
|
|
|
+ case "WILLEXPIRE":
|
|
|
+ return "合同即将过期";
|
|
|
+ case "DEADLINE":
|
|
|
+ return "合同流签(合同过期)";
|
|
|
+ case "RELIEVED":
|
|
|
+ return "已解除";
|
|
|
+ case "INVALID":
|
|
|
+ return "合同已失效";
|
|
|
+ case "EXCEPTION":
|
|
|
+ return "合同异常";
|
|
|
+ default:
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getApproveStatus(String approveStatus) {
|
|
|
+ switch (approveStatus) {
|
|
|
+ case "PENDING":
|
|
|
+ return "待签署";
|
|
|
+ case "ACCEPT":
|
|
|
+ return "已签署";
|
|
|
+ case "REJECT":
|
|
|
+ return "拒绝 ";
|
|
|
+ case "DEADLINE":
|
|
|
+ return "过期没人处理";
|
|
|
+ case "CANCEL":
|
|
|
+ return "流程已撤回";
|
|
|
+ case "STOP":
|
|
|
+ return "流程已终止";
|
|
|
+ case "WAITPICKUP":
|
|
|
+ return "待领取";
|
|
|
+ case "FILLPENDING":
|
|
|
+ return "待填写";
|
|
|
+ case "FILLACCEPT":
|
|
|
+ return "填写完成";
|
|
|
+ case "FORWARD":
|
|
|
+ return "已转他人处理";
|
|
|
+ case "RELIEVED":
|
|
|
+ return "已解除";
|
|
|
+ case "FILLREJECT":
|
|
|
+ return "拒绝填写";
|
|
|
+ case "EXCEPTION":
|
|
|
+ return "异常";
|
|
|
+ default:
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static void main(String[] args) throws TencentCloudSDKException {
|
|
|
+ String[] flowIds = {"yD3g7UUckpmzhmhtU1UyFt71fypQygwg"};
|
|
|
|
|
|
- WeChatContractUtil wccUtil = new WeChatContractUtil();
|
|
|
- DescribeTemplatesResponse resp = wccUtil.getTemplateList(SuperProxyOperatorOpenId);
|
|
|
+ DescribeFlowDetailInfoResponse res = describeFlowDetailInfo(setAgent(SuperProxyOperatorOpenId), flowIds);
|
|
|
|
|
|
- System.err.println(DescribeTemplatesResponse.toJsonString(resp));
|
|
|
+ System.err.println(DescribeTemplatesResponse.toJsonString(res));
|
|
|
}
|
|
|
|
|
|
}
|