private SdkResponse <DocumentAddResult> AddDocumentByFile(SDKClient client, string contractId) { string path = "C:\\Users\\Richard Cheung\\Documents\\契约锁\\测试\\AA.pdf"; //待添加的文件路径 Stream file = new FileStream(path, FileMode.Open); //指定文件名称,以及文件类型,比如此时的文件为pdf DocumentAddByFileRequest request = new DocumentAddByFileRequest(contractId, "根据文件添加文档", file, "pdf"); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("根据文件添加合同文档请求服务器失败,失败原因:" + e.Message); } SdkResponse <DocumentAddResult> sdkResponse = HttpJsonConvert.DeserializeResponse <DocumentAddResult>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("根据文件添加合同文档失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// 发送并处理快捷签约请求 /// </summary> /// <param name="client"></param> /// <param name="contract">签约的合同对象</param> /// <returns>签约URL-浏览器打开可继续签约</returns> public string Process(SDKClient client, Contract contract) { DraftContractRequest request = new DraftContractRequest(contract); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("起草签约失败, 失败原因: " + e.Message); } SdkResponse <SignResult> signRS = HttpJsonConvert.DeserializeResponse <SignResult>(response); if (!signRS.Success) { throw new Exception("起草签约失败, 失败原因: " + signRS.Message); } Console.WriteLine("Contract No: {0} , you can access URL in the Explorer to continue the contract signing:\n {1}\n", signRS.Result.ContractId, signRS.Result.SignUrl); return(signRS.Result.SignUrl); }
private SdkResponse <Object> Audit(SDKClient client, string contractId) { ContractAuditRequest request = new ContractAuditRequest(); request.ContractId = contractId; request.Pass = true; //审批结果,True:通过,False:不通过,若不通过合同无法继续签署 request.Comment = "符合要求,审批通过"; //审批原因 string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("审批合同请求服务器失败,失败原因:" + e.Message); } SdkResponse <Object> sdkResponse = HttpJsonConvert.DeserializeResponse <Object>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("审批合同失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// 企业用户重新认证企业 /// </summary> /// <param name="client"></param> /// <param name="realNameAuth">认证对象</param> /// <returns></returns> public string EnterpriseReCertification(SDKClient client, RealNameAuth realNameAuth) { if (!RealNameAuth.AUTH_TYPE_ENTERPRISE.Equals(realNameAuth.type)) { throw new Exception("EnterpriseReCertification失败, 失败原因: 用户类型必须为 RealNameAuth.AUTH_TYPE_ENTERPRISE"); } string response = null; try { RecertificationRequest request = new RecertificationRequest(realNameAuth); response = client.Service(request); } catch (Exception e) { throw new Exception("EnterpriseReCertification失败,失败原因: " + e.Message); } SdkResponse <NoCustomResult> sdkResponse = HttpJsonConvert.DeserializeResponse <NoCustomResult>(response); if (!sdkResponse.Success) { throw new Exception("EnterpriseReCertification失败,失败原因: " + sdkResponse.Message); } return(sdkResponse.Success.ToString()); }
private SdkResponse <DocumentAddResult> AddDocumnetByTemplate(SDKClient client, string contractId) { string templateId = "2492236993899110515"; //待添加的文件模板Id,合同模板请前往契约锁云平台维护 DocumentAddByTemplateRequest request = new DocumentAddByTemplateRequest(contractId, "添加模板", templateId); // 如果文件模板为参数模板,添加参数内容 request.AddTemplateParam(new TemplateParam("接收方1", "契约锁")); request.AddTemplateParam(new TemplateParam("接收方2", "电子合同")); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("根据模板添加合同文档请求服务器失败,失败原因:" + e.Message); } SdkResponse <DocumentAddResult> sdkResponse = HttpJsonConvert.DeserializeResponse <DocumentAddResult>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("根据模板添加合同文档添加失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/** * * 利用业务分类配置进行公章签署 * 签署位置需要在业务分类中指定,若没指定则需要传递签署位置 * * */ private SdkResponse <Object> CompanySealSignByCategoryConfig(SDKClient client, string contractId) { SdkResponse <Contract> detail = this.Detail(client, contractId); ContractSignCompanyRequest request = new ContractSignCompanyRequest(); request.ContractId = contractId; string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("公章签署请求服务器失败,失败原因:" + e.Message); } SdkResponse <Object> sdkResponse = HttpJsonConvert.DeserializeResponse <Object>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("公章签署失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// 发送并处理快捷签约请求 /// </summary> /// <param name="client"></param> /// <param name="quickContract">签约的合同对象</param> private new void Process(SDKClient client, Contract quickContract) { QuickSignRequest request = new QuickSignRequest(quickContract); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("快捷签约合同失败,失败原因: " + e.Message); } SdkResponse <SignResult> signRS = HttpJsonConvert.DeserializeResponse <SignResult>(response); if (!signRS.Success) { throw new Exception("快捷签约合同失败,失败原因: " + signRS.Message); } string DOWNLOAD_URL = client.ServerUrl + RequestPathConstant.DOWNLOAD_CONTRACT + "?appKey=" + client.AccessToken + "&appSecret=" + client.AccessSecret + "&storeNo=" + signRS.Result.ContractId; Console.WriteLine("Contract No: {0} , you can download the file:\n a) call Program.cs#Fetch method with Store No {1}\n b) access URL in the Explorer: {2}\n", signRS.Result.ContractId, signRS.Result.ContractId, DOWNLOAD_URL); }
private SdkResponse <Object> CompanySealSign(SDKClient client, string contractId, string documentId1, string documentId2) { ContractSignCompanyRequest request = new ContractSignCompanyRequest(); request.ContractId = contractId; //若公章未指定签署位置,需要在签署时指定签署位置 //若制定了签署位置,优先使用签署位置中的位置进行签署 /* * Stamper companyStamper = new Stamper(); * companyStamper.Type = "COMPANY"; * companyStamper.OffsetX = 0.2; * companyStamper.OffsetY = 0.3; * companyStamper.Page = 1; * companyStamper.DocumentId = documentId1; * companyStamper.SealId = "2490828768980361630"; * * Stamper companyTimeStamp = new Stamper(); * companyTimeStamp.Type = "TIMESTAMP"; * companyTimeStamp.OffsetX = 0.4; * companyTimeStamp.OffsetY = 0.2; * companyTimeStamp.Page = 1; * companyTimeStamp.DocumentId = documentId1; * companyTimeStamp.SealId = "2490828768980361630"; * * //骑缝章签署需要文档页数在一页以上 * Stamper acrossPageStamper = new Stamper(); * acrossPageStamper.Type = "ACROSS_PAGE"; * acrossPageStamper.OffsetY = 0.2; * acrossPageStamper.DocumentId = documentId1; * acrossPageStamper.SealId = "2490828768980361630"; * * request.AddStampers(companyStamper); * request.AddStampers(companyTimeStamp); * request.AddStampers(acrossPageStamper); */ string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("公章签署请求服务器失败,失败原因:" + e.Message); } SdkResponse <Object> sdkResponse = HttpJsonConvert.DeserializeResponse <Object>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("公章签署失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/** * 创建草稿 **/ private SdkResponse <Contract> Draft(SDKClient client) { ContractDraftRequest request = new ContractDraftRequest(); Contract contract = new Contract(); contract.Subject = "合同主题名称"; //添加平台方签署方 Signatory platformSignatory = new Signatory("COMPANY", new User("张忱昊", "17621699044", "MOBILE"), 1); platformSignatory.TenantName = "大头橙橙汁公司";//平台方公司名称 //添加平台方签署流程,可根据需要调整 //目前平台方签署流程为: (1)公章签署(2)法人章签署 // 公章签署流程,并设置签署公章ID SignAction sealAction = new SignAction("COMPANY", 1); sealAction.SealId = "2490828768980361630"; platformSignatory.AddAction(sealAction); contract.AddSignatory(platformSignatory); //添加个人签署方,并设置个人签署方需要上传的附件内容 Signatory personalSignatory = new Signatory("PERSONAL", new User("邓茜茜", "15021504325", "MOBILE"), 2); personalSignatory.TenantName = "邓茜茜";//接收方名称 contract.AddSignatory(personalSignatory); //设置合同基本信息 contract.ExpireTime = "2020-07-28 23:59:59"; //设置合同过期时间,合同过期时间需要晚于发起时间 contract.Send = false; //合同不发起 request.Contract = contract; string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("创建合同草稿请求服务器失败,失败原因" + e.Message); } SdkResponse <Contract> sdkResponse = HttpJsonConvert.DeserializeResponse <Contract>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("创建合同草稿失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/** * 用户通过配置好的业务分类进行合同发起 * 需在业务分类里配置好将要发起的合同文件或合同模板 * 配置好整个签署流程,以及签署流程中使用的印章 * **/ private SdkResponse <Contract> DraftByCategory(SDKClient client) { Contract draftContract = new Contract(); draftContract.Subject = "合同主体"; // 设置合同名称 draftContract.Category = new Category("2584280095237849689"); //设置将要使用的业务分类配置 draftContract.AddTemplateParam(new TemplateParam("接收方2", "发起方填参")); //若业务分类配置了参数模板,进行发起方填参 draftContract.AddTemplateParam(new TemplateParam("接收方1", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方3", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方4", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方5", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方6", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方7", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方8", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方9", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方10", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方11", "发起方填参2")); draftContract.AddTemplateParam(new TemplateParam("接收方12", "发起方填参2")); //设置 合同接收方,该设置的合同接收方需要与业务分类配置的接收方流程一致 Signatory companySignatory = new Signatory("COMPANY", new User("17621699044", "MOBILE"), 1); companySignatory.TenantName = "大头橙橙汁公司"; draftContract.AddSignatory(companySignatory); Signatory personalSignatory = new Signatory("PERSONAL", new User("15021504325", "MOBILE"), 2); personalSignatory.TenantName = "邓茜茜"; draftContract.AddSignatory(personalSignatory); draftContract.Send = true; //设置发起默认发起,业务分类中必须要有可用的签署文件 string response = null; try { response = client.Service(new ContractDraftRequest(draftContract)); } catch (Exception e) { throw new Exception("创建合同草稿请求服务器失败,错误原因:" + e.Message); } SdkResponse <Contract> sdkResponse = HttpJsonConvert.DeserializeResponse <Contract>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("创建合同草稿失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
private SdkResponse <Object> LpSign(SDKClient client, string contractId, string documentId1, string documentId2) { ContractSignLPRequest request = new ContractSignLPRequest(); request.ContractId = contractId; //若法人章未指定签署位置,需要在签署时指定签署位置 //若制定了签署位置,优先使用签署位置中的位置进行签署 /* * Stamper lpStamper = new Stamper(); * lpStamper.Type = "LP"; * lpStamper.OffsetX = 0.2; * lpStamper.OffsetY = 0.3; * lpStamper.Page = 1; * lpStamper.DocumentId = documentId1; * * Stamper lpTimeStamp = new Stamper(); * lpTimeStamp.Type = "TIMESTAMP"; * lpTimeStamp.OffsetX = 0.4; * lpTimeStamp.OffsetY = 0.2; * lpTimeStamp.Page = 1; * lpTimeStamp.DocumentId = documentId1; * request.AddStampers(lpStamper); * request.AddStampers(lpTimeStamp); */ string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("法人章签署请求服务器失败,失败原因:" + e.Message); } SdkResponse <Object> sdkResponse = HttpJsonConvert.DeserializeResponse <Object>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("法人章签署失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// 查询签约详情 /// </summary> /// <param name="client"></param> /// <param name="contractId">合同编号</param> /// <returns></returns> public SdkResponse <QueryContractResult> QueryContract(SDKClient client, string contractId) { QueryContractRequest request = new QueryContractRequest(contractId); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("QueryContract失败,失败原因: " + e.Message); } SdkResponse <QueryContractResult> sdkResponse = HttpJsonConvert.DeserializeResponse <QueryContractResult>(response); if (!sdkResponse.Success) { throw new Exception("QueryContract失败,失败原因: " + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// Ping服务器是否联通 /// </summary> /// <param name="client"></param> /// <returns></returns> public SdkResponse <PingResult> Ping(SDKClient client) { PingRequest request = new PingRequest(); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("Ping服务器失败,失败原因: " + e.Message); } SdkResponse <PingResult> sdkResponse = HttpJsonConvert.DeserializeResponse <PingResult>(response); if (!sdkResponse.Success) { throw new Exception("Ping服务器失败,失败原因: " + sdkResponse.Message); } return(sdkResponse); }
/// <summary> /// 用户实名认证 /// </summary> /// <param name="client"></param> /// <param name="realNameAuth">实名对象</param> /// <returns></returns> public string RealName(SDKClient client, RealNameAuth realNameAuth) { string response = null; try { RealNameRequest request = new RealNameRequest(realNameAuth); response = client.Service(request); } catch (Exception e) { throw new Exception("RealNameAuth失败,失败原因: " + e.Message); } SdkResponse <NoCustomResult> sdkResponse = HttpJsonConvert.DeserializeResponse <NoCustomResult>(response); if (!sdkResponse.Success) { throw new Exception("RealNameAuth失败,失败原因: " + sdkResponse.Message); } return(sdkResponse.Success.ToString()); }
/// <summary> /// 继续签约的链接 /// </summary> /// <param name="client"></param> /// <param name="contractId">合同编号</param> /// <returns></returns> public string FetchSignUrl(SDKClient client, string contractId) { FetchSignUrlRequest request = new FetchSignUrlRequest(contractId); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("FetchSignUrl失败,失败原因: " + e.Message); } SdkResponse <SignResult> sdkResponse = HttpJsonConvert.DeserializeResponse <SignResult>(response); if (!sdkResponse.Success) { throw new Exception("FetchSignUrl失败,失败原因: " + sdkResponse.Message); } return(sdkResponse.Result.SignUrl); }
private SdkResponse <Contract> Detail(SDKClient client, string contractId) { ContractDetailRequest detailRequest = new ContractDetailRequest() { ContractId = contractId }; string response = null; try { response = client.Service(detailRequest); } catch (Exception e) { throw new Exception("查询合同详情请求服务器失败,错误原因:" + e.Message); } SdkResponse <Contract> sdkResponse = HttpJsonConvert.DeserializeResponse <Contract>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("查询合同详情失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
private SdkResponse <PageUrlResult> GerenateSignUrl(SDKClient client, string contractId) { ContractPageRequest request = new ContractPageRequest(); request.ContractId = contractId; //内嵌页面签署合同ID request.User = new User("15021504325", "MOBILE"); //内嵌页面签署人信息 string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("生成签署链接请求服务器失败,失败原因:" + e.Message); } SdkResponse <PageUrlResult> sdkResponse = HttpJsonConvert.DeserializeResponse <PageUrlResult>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("生成签署链接失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }
private SdkResponse <Object> Send(SDKClient client, Contract contract, string documentId1, string documentId2) { ContractSendRequest request = new ContractSendRequest(); request.ContractId = contract.Id; string platformSignatoryId = null; string personalSignatoryId = null; string companyActionId = null; // 获取对应的ActionId与SignatoryId foreach (Signatory signatory in contract.Signatories) { //获取平台方公司Signatory,确保TenantName替换为自己的公司名称 if (signatory.TenantName.Equals("大头橙橙汁公司") && signatory.TenantType.Equals("COMPANY")) { platformSignatoryId = signatory.Id; foreach (SignAction action in signatory.Actions) { if (action.Type.Equals("COMPANY")) { companyActionId = action.Id; } } } //获取个人签署方,可通过TenantName确定精确的签署方 if (signatory.TenantType.Equals("PERSONAL")) { personalSignatoryId = signatory.Id; } } //指定签署位置 //发起方(公司):印章签署位置、法人章签署位置、时间戳位置 Stamper sealStamper = new Stamper(); sealStamper.DocumentId = documentId1; sealStamper.ActionId = companyActionId; sealStamper.Type = "COMPANY"; // 绝对位置定位:页数、X、Y定位 sealStamper.Page = 1; sealStamper.OffsetX = 0.1; sealStamper.OffsetY = 0.2; // 关键字位置定位:keyword,keywordIndex,X,Y //sealStamper.Keyword = "甲方签字"; //确保文件中包含该关键字 //sealStamper.KeywordIndex = 1; //sealStamper.OffsetX = 0.0; //sealStamper.OffsetY = 0.0; Stamper timeStamper = new Stamper(); timeStamper.DocumentId = documentId1; timeStamper.ActionId = companyActionId; timeStamper.Type = "TIMESTAMP"; timeStamper.Page = 1; timeStamper.OffsetX = 0.3; timeStamper.OffsetY = 0.5; //个人签署方 签署位置 Stamper personalStamper = new Stamper(); personalStamper.DocumentId = documentId1; personalStamper.SignatoryId = personalSignatoryId; personalStamper.Type = "PERSONAL"; personalStamper.Page = 1; personalStamper.OffsetX = 0.7; personalStamper.OffsetY = 0.5; request.AddStamper(sealStamper); request.AddStamper(timeStamper); request.AddStamper(personalStamper); string response = null; try { response = client.Service(request); } catch (Exception e) { throw new Exception("发起合同请求服务器失败,失败原因:" + e.Message); } SdkResponse <Object> sdkResponse = HttpJsonConvert.DeserializeResponse <Object>(response); if (!sdkResponse.Code.Equals(0)) { throw new Exception("发起合同失败,失败原因:" + sdkResponse.Message); } return(sdkResponse); }