signflow_launch.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 signFlowCreateByFile():
  9. """
  10. 基于文件发起签署
  11. :return:
  12. """
  13. body = {
  14. "signFlowConfig": {
  15. "noticeTypes": {
  16. "noticeTypes": "1"
  17. },
  18. "signConfig": {
  19. "availableSignClientTypes": "1",
  20. "showBatchDropSealButton": True
  21. },
  22. "autoFinish": True,
  23. "notifyUrl": "",
  24. "signFlowTitle": "小****同.pdf"
  25. },
  26. "signers": [{
  27. "signConfig": {
  28. "forcedReadingTime": 5,
  29. "signOrder": 1
  30. },
  31. "signFields": [{
  32. "signFieldType": 0,
  33. "normalSignFieldConfig": {
  34. "signFieldPosition": {
  35. "positionY": "331.422",
  36. "positionPage": 4,
  37. "positionX": "51.306"
  38. },
  39. "signFieldStyle": 1
  40. },
  41. "fileId": "95ce531*******1b"
  42. }],
  43. "signerType": 0,
  44. "psnSignerInfo": {
  45. "psnAccount": "15*****7"
  46. }
  47. }, {
  48. "signConfig": {
  49. "signOrder": 3
  50. },
  51. "orgSignerInfo": {
  52. "orgName": "阳**苑",
  53. "orgSignerInfo": {
  54. "$ref": "@"
  55. }
  56. },
  57. "signFields": [{
  58. "signFieldType": 0,
  59. "normalSignFieldConfig": {
  60. "signFieldPosition": {},
  61. "signFieldStyle": 1
  62. },
  63. "fileId": "95ce******5831b"
  64. }],
  65. "signerType": 1
  66. }],
  67. "docs": [{
  68. "fileName": "小*****同.pdf",
  69. "fileId": "95c*****31b"
  70. }]
  71. } # 构建请求body体
  72. api_path = "/v3/sign-flow/create-by-file" # 拼接请求路径
  73. method = esigntool.httpMethodEnum.POST # 声明请求方法
  74. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  75. method, api_path, body) # 签名并构造签名鉴权json请求头
  76. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  77. print(resp)
  78. print(resp.text)
  79. return resp
  80. @esign_run_print_outer
  81. def signUrl():
  82. """
  83. 获取合同文件签署链接
  84. :return:
  85. """
  86. body = {
  87. "clientType": "ALL",
  88. "needLogin": True,
  89. "operator": {
  90. "psnAccount": "183****0101"
  91. },
  92. "urlType": 2
  93. } # 构建请求body体
  94. sign_flowId = "23423****25435" # 声明请求参数
  95. api_path = "/v3/sign-flow/{}/sign-url".format(sign_flowId) # 拼接请求路径
  96. method = esigntool.httpMethodEnum.POST # 请求方法
  97. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  98. method, api_path, body) # 签名并构造签名鉴权json请求头
  99. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送http请求
  100. print(resp)
  101. print(resp.text)
  102. return resp
  103. @esign_run_print_outer
  104. def batchSignUrl():
  105. """
  106. 获取批量签页面链接(多流程)
  107. :return:
  108. """
  109. body = {
  110. "operatorId": "c7e0029472914ce4a3xxxe7",
  111. "redirectUrl": "xxx",
  112. "signFlowIds": ["ba619b6d0***bf8e9xxe4", "7b90e0d09***29a67dx53"]
  113. } # 构建请求body体
  114. api_path = "/v3/sign-flow/batch-sign-url" # 拼接请求路径
  115. method = esigntool.httpMethodEnum.POST
  116. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  117. method, api_path, body) # 签名并构造签名鉴权json请求头
  118. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送http请求
  119. print(resp)
  120. print(resp.text)
  121. return resp
  122. if __name__ == '__main__':
  123. signFlowCreateByFile() # 基于文件发起签署
  124. signUrl() # 获取合同文件签署链接
  125. batchSignUrl() # 获取批量签页面链接(多流程)