# -*- coding: UTF-8 -*- import esigntool import requests from esigntool import esign_run_print_outer # 合同模板类API config = esigntool.config() # 初始化配置类 @esign_run_print_outer def templatePageCreate(): """ 获取制作合同模板页面 :return: """ body = { "docTemplateName": "某公司的劳动合同模板", "docTemplateType": 0, "fileId": "0e99de7ce***9db2cd69", "redirectUrl": "https://www.xxx.cn/" } # 构建请求body体 api_path = "/v3/doc-templates/doc-template-create-url" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求 print(resp.text) return resp @esign_run_print_outer def templateEditUrl(): """ 获取编辑合同模板页面 :return: """ body = { "redirectUrl": "https://www.xxx.com/" } # 构建请求body体 docTemplateId = "fs*********fd" # 声明请求变量 api_path = "/v3/doc-templates/{}/doc-template-edit-url".format(docTemplateId) # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送网络请求 print(resp.text) return resp @esign_run_print_outer def templateDetail(): """ 查询合同模板中控件详情 :return: """ docTemplateId = "fs*********fd" # 声明请求变量 api_path = "/v3/doc-templates/{}".format(docTemplateId) # 拼接请求路径 method = esigntool.httpMethodEnum.GET # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求 print(resp.text) return resp @esign_run_print_outer def templateCreateDoc(): """ 填写模板生成文件 :return: """ body = { "docTemplateId": "8726f6b**03a56d", "fileName": "某公司的交易协议签署文件", "components": [ { "componentId": "59af7766***36ef41b", "componentKey": "", "componentValue": "这里是填充的文本" }, { "componentId": "7315e9af**72d2dac40", "componentKey": "", "componentValue": "2022/01/01" } ] } api_path = "/v3/files/create-by-doc-template" # 拼接请求路径 method = esigntool.httpMethodEnum.POST # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送网络请求 print(resp.text) return resp @esign_run_print_outer def templatePageList(): """ 查询合同模板列表 :return: """ pageNum = "1" # 声明请求变量 pageSize = "10" # 声明请求变量 api_path = "/v3/doc-templates?pageNum={}&pageSize={}".format(pageNum, pageSize) # 拼接请求路径 method = esigntool.httpMethodEnum.GET # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求 print(resp.text) return resp def templateDelete(): """ 删除合同模板 :return: """ docTemplateId = "123********gs" # 声明请求变量 api_path = "/v3/doc-templates/{}".format(docTemplateId) # 拼接请求路径 method = esigntool.httpMethodEnum.DELETE # 声明请求方法 json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path) # 签名并构造签名鉴权json请求头 resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求 print(resp.text) return resp if __name__ == '__main__': templatePageCreate() # 获取制作合同模板页面 templateEditUrl() # 获取编辑合同模板页面 templateDetail() # 查询合同模板中控件详情 templateCreateDoc() # 填写模板生成文件 templatePageList() # 查询合同模板列表 templateDelete() # 删除合同模板