template.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # -*- coding: UTF-8 -*-
  2. import esigntool
  3. import requests
  4. from esigntool import esign_run_print_outer
  5. # 合同模板类API
  6. config = esigntool.config() # 初始化配置类
  7. @esign_run_print_outer
  8. def templatePageCreate():
  9. """
  10. 获取制作合同模板页面
  11. :return:
  12. """
  13. body = {
  14. "docTemplateName": "某公司的劳动合同模板",
  15. "docTemplateType": 0,
  16. "fileId": "0e99de7ce***9db2cd69",
  17. "redirectUrl": "https://www.xxx.cn/"
  18. } # 构建请求body体
  19. api_path = "/v3/doc-templates/doc-template-create-url" # 拼接请求路径
  20. method = esigntool.httpMethodEnum.POST # 声明请求方法
  21. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  22. method, api_path, body) # 签名并构造签名鉴权json请求头
  23. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  24. print(resp.text)
  25. return resp
  26. @esign_run_print_outer
  27. def templateEditUrl():
  28. """
  29. 获取编辑合同模板页面
  30. :return:
  31. """
  32. body = {
  33. "redirectUrl": "https://www.xxx.com/"
  34. } # 构建请求body体
  35. docTemplateId = "fs*********fd" # 声明请求变量
  36. api_path = "/v3/doc-templates/{}/doc-template-edit-url".format(docTemplateId) # 拼接请求路径
  37. method = esigntool.httpMethodEnum.POST # 声明请求方法
  38. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  39. method, api_path, body) # 签名并构造签名鉴权json请求头
  40. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送网络请求
  41. print(resp.text)
  42. return resp
  43. @esign_run_print_outer
  44. def templateDetail():
  45. """
  46. 查询合同模板中控件详情
  47. :return:
  48. """
  49. docTemplateId = "fs*********fd" # 声明请求变量
  50. api_path = "/v3/doc-templates/{}".format(docTemplateId) # 拼接请求路径
  51. method = esigntool.httpMethodEnum.GET # 声明请求方法
  52. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  53. method, api_path) # 签名并构造签名鉴权json请求头
  54. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求
  55. print(resp.text)
  56. return resp
  57. @esign_run_print_outer
  58. def templateCreateDoc():
  59. """
  60. 填写模板生成文件
  61. :return:
  62. """
  63. body = {
  64. "docTemplateId": "8726f6b**03a56d",
  65. "fileName": "某公司的交易协议签署文件",
  66. "components": [
  67. {
  68. "componentId": "59af7766***36ef41b",
  69. "componentKey": "",
  70. "componentValue": "这里是填充的文本"
  71. },
  72. {
  73. "componentId": "7315e9af**72d2dac40",
  74. "componentKey": "",
  75. "componentValue": "2022/01/01"
  76. }
  77. ]
  78. }
  79. api_path = "/v3/files/create-by-doc-template" # 拼接请求路径
  80. method = esigntool.httpMethodEnum.POST # 声明请求方法
  81. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  82. method, api_path, body) # 签名并构造签名鉴权json请求头
  83. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送网络请求
  84. print(resp.text)
  85. return resp
  86. @esign_run_print_outer
  87. def templatePageList():
  88. """
  89. 查询合同模板列表
  90. :return:
  91. """
  92. pageNum = "1" # 声明请求变量
  93. pageSize = "10" # 声明请求变量
  94. api_path = "/v3/doc-templates?pageNum={}&pageSize={}".format(pageNum, pageSize) # 拼接请求路径
  95. method = esigntool.httpMethodEnum.GET # 声明请求方法
  96. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  97. method, api_path) # 签名并构造签名鉴权json请求头
  98. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求
  99. print(resp.text)
  100. return resp
  101. def templateDelete():
  102. """
  103. 删除合同模板
  104. :return:
  105. """
  106. docTemplateId = "123********gs" # 声明请求变量
  107. api_path = "/v3/doc-templates/{}".format(docTemplateId) # 拼接请求路径
  108. method = esigntool.httpMethodEnum.DELETE # 声明请求方法
  109. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  110. method, api_path) # 签名并构造签名鉴权json请求头
  111. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送网络请求
  112. print(resp.text)
  113. return resp
  114. if __name__ == '__main__':
  115. templatePageCreate() # 获取制作合同模板页面
  116. templateEditUrl() # 获取编辑合同模板页面
  117. templateDetail() # 查询合同模板中控件详情
  118. templateCreateDoc() # 填写模板生成文件
  119. templatePageList() # 查询合同模板列表
  120. templateDelete() # 删除合同模板