# -*- coding: UTF-8 -*- import esigntool import requests from esigntool import esign_run_print_outer # 合同文件签署服务API - 签署流程 - 发起类 config = esigntool.config() # 初始化配置类 @esign_run_print_outer def signFlowCreateByFile(): """ 基于文件发起签署 :return: """ body = { "signFlowConfig": { "noticeTypes": { "noticeTypes": "1" }, "signConfig": { "availableSignClientTypes": "1", "showBatchDropSealButton": True }, "autoFinish": True, "notifyUrl": "", "signFlowTitle": "小****同.pdf" }, "signers": [{ "signConfig": { "forcedReadingTime": 5, "signOrder": 1 }, "signFields": [{ "signFieldType": 0, "normalSignFieldConfig": { "signFieldPosition": { "positionY": "331.422", "positionPage": 4, "positionX": "51.306" }, "signFieldStyle": 1 }, "fileId": "95ce531*******1b" }], "signerType": 0, "psnSignerInfo": { "psnAccount": "15*****7" } }, { "signConfig": { "signOrder": 3 }, "orgSignerInfo": { "orgName": "阳**苑", "orgSignerInfo": { "$ref": "@" } }, "signFields": [{ "signFieldType": 0, "normalSignFieldConfig": { "signFieldPosition": {}, "signFieldStyle": 1 }, "fileId": "95ce******5831b" }], "signerType": 1 }], "docs": [{ "fileName": "小*****同.pdf", "fileId": "95c*****31b" }] } # 构建请求body体 api_path = "/v3/sign-flow/create-by-file" # 拼接请求路径 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) print(resp.text) return resp @esign_run_print_outer def signUrl(): """ 获取合同文件签署链接 :return: """ body = { "clientType": "ALL", "needLogin": True, "operator": { "psnAccount": "183****0101" }, "urlType": 2 } # 构建请求body体 sign_flowId = "23423****25435" # 声明请求参数 api_path = "/v3/sign-flow/{}/sign-url".format(sign_flowId) # 拼接请求路径 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) # 发送http请求 print(resp) print(resp.text) return resp @esign_run_print_outer def batchSignUrl(): """ 获取批量签页面链接(多流程) :return: """ body = { "operatorId": "c7e0029472914ce4a3xxxe7", "redirectUrl": "xxx", "signFlowIds": ["ba619b6d0***bf8e9xxe4", "7b90e0d09***29a67dx53"] } # 构建请求body体 api_path = "/v3/sign-flow/batch-sign-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) # 发送http请求 print(resp) print(resp.text) return resp if __name__ == '__main__': signFlowCreateByFile() # 基于文件发起签署 signUrl() # 获取合同文件签署链接 batchSignUrl() # 获取批量签页面链接(多流程)