attachments_change.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 addUnsignedFiles():
  9. """
  10. 追加待签文件
  11. :return:
  12. """
  13. body = {
  14. "unsignedFiles": [
  15. {
  16. "fileId": "ea3151a8d***a53d3f4c",
  17. "fileName": "入职证明.pdf"
  18. }
  19. ]
  20. }
  21. # 构建请求body体
  22. sign_flowId = "df********grgter" # 声明变量入参
  23. api_path = "/v3/sign-flow/{}/unsigned-files".format(sign_flowId) # 拼接请求路径
  24. method = esigntool.httpMethodEnum.POST # 声明请求方法
  25. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  26. method, api_path, body) # 计算签名并构造签名鉴权json请求头
  27. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  28. print(resp.text)
  29. return resp
  30. @esign_run_print_outer
  31. def deleteUnsignedFiles():
  32. """
  33. 删除待签署文件
  34. :return:
  35. """
  36. sign_flowId = "df********grgter" # 声明变量入参
  37. sign_FieldIds = "urerutheirt" # 声明变量入参
  38. api_path = "/v3/sign-flow/{}/unsigned-files?fileIds={}".format(sign_flowId, sign_FieldIds) # 拼接请求路径
  39. method = esigntool.httpMethodEnum.DELETE # 声明请求方法
  40. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  41. method, api_path) # 签名并构造签名鉴权json请求头
  42. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  43. print(resp.text)
  44. return resp
  45. @esign_run_print_outer
  46. def addAttachments():
  47. """
  48. 追加附属材料
  49. :return:
  50. """
  51. body = {
  52. "attachmentList": [
  53. {
  54. "fileId": "ea3151***a53d3f4c",
  55. "fileName": "入职手册.pdf"
  56. }
  57. ]
  58. }
  59. # 构建请求body体
  60. sign_flowId = "df********grgter" # 声明变量入参
  61. api_path = "/v3/sign-flow/{}/attachments".format(sign_flowId) # 拼接请求路径
  62. method = esigntool.httpMethodEnum.POST # 声明请求方法
  63. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  64. method, api_path, body) # 计算签名并构造签名鉴权json请求头
  65. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  66. print(resp.text)
  67. return resp
  68. @esign_run_print_outer
  69. def deleteAttachments():
  70. """
  71. 删除附属材料
  72. :return:
  73. """
  74. sign_flowId = "df********grgter" # 声明变量入参
  75. sign_FieldIds = "xxx1,xxx2" # 声明变量入参
  76. api_path = "/v3/sign-flow/{}/attachments?fileIds={}".format(sign_flowId, sign_FieldIds) # 拼接请求路径
  77. method = esigntool.httpMethodEnum.DELETE # 声明请求方法
  78. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  79. method, api_path) # 签名并构造签名鉴权json请求头
  80. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  81. print(resp.text)
  82. return resp
  83. if __name__ == '__main__':
  84. addUnsignedFiles() # 追加待签文件
  85. deleteUnsignedFiles() # 删除待签署文件
  86. addAttachments() # 追加附属材料
  87. deleteAttachments() # 删除附属材料