psn_seals.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import requests
  2. import esigntool
  3. from esigntool import esign_run_print_outer
  4. # 印章服务API
  5. config = esigntool.config() # 初始化配置类
  6. @esign_run_print_outer
  7. def createPsn_seals():
  8. """
  9. 创建个人模板印章
  10. :return:
  11. """
  12. # 构建请求body体
  13. body = {
  14. "psnId": "c7e002***0541e7",
  15. "sealName": "这是一个自定义的名称",
  16. "sealTemplateStyle": "SQUARE_LEFT_BORDER",
  17. "sealSize": "20_20",
  18. "sealColor": "RED",
  19. "sealSuffix": "2",
  20. "sealOldStyle": "OLD_1",
  21. "sealOpacity": "100"
  22. }
  23. api_path = "/v3/seals/psn-seals/create-by-template" # 拼接请求路径
  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 create_image():
  32. """
  33. 创建个人图片印章
  34. :return:
  35. """
  36. # 构建请求body体
  37. body = {
  38. "psnId": "c7e0029***0541e7",
  39. "sealImageFileKey": "$c3c7170e-xx-xx-xx-xx",
  40. "sealName": "这是一个自定义的印章名称",
  41. "sealWidth": "20",
  42. "sealHeight": "10",
  43. "sealColor": "RED"
  44. }
  45. api_path = "/v3/seals/psn-seals/create-by-image" # 拼接请求路径
  46. method = esigntool.httpMethodEnum.POST # 声明请求方法
  47. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  48. method, api_path, body) # 签名并构造签名鉴权json请求头
  49. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  50. print(resp.text)
  51. return resp
  52. @esign_run_print_outer
  53. def seals_query():
  54. """
  55. 查询个人印章列表
  56. :return:
  57. """
  58. psnId = "c7e00290541e7"
  59. pageNum = "1"
  60. pageSize = "20"
  61. api_path = "/v3/seals/psn-seal-list?psnId={}&pageNum={}&pageSize={}".format(psnId, pageNum, pageSize) # 拼接请求路径
  62. print(api_path)
  63. method = esigntool.httpMethodEnum.GET # 声明请求方法
  64. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  65. method, api_path) # 签名并构造签名鉴权json请求头
  66. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  67. print(resp.text)
  68. return resp
  69. @esign_run_print_outer
  70. def sealsinfo_query():
  71. """
  72. 查询指定印章详情
  73. :return:
  74. """
  75. psnId = "c7e0****41e7"
  76. sealId = "1caebb40***31f7f95087de"
  77. api_path = "/v3/seals/psn-seal-info?psnId={}&sealId={}".format(psnId, sealId) # 拼接请求路径
  78. print(api_path)
  79. method = esigntool.httpMethodEnum.GET # 声明请求方法
  80. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  81. method, api_path) # 签名并构造签名鉴权json请求头
  82. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  83. print(resp.text)
  84. return resp
  85. @esign_run_print_outer
  86. def change_seals():
  87. """
  88. 设置个人默认印章
  89. :return:
  90. """
  91. # 构建请求body体
  92. body = {
  93. "psnId": "c7e0029***41e7",
  94. "sealId": "d2749c50-xx-xx-xx-ce4482c7747f"
  95. }
  96. api_path = "/v3/seals/psn-seals/set-default-seal" # 拼接请求路径
  97. method = esigntool.httpMethodEnum.POST # 声明请求方法
  98. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  99. method, api_path, body) # 签名并构造签名鉴权json请求头
  100. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  101. print(resp.text)
  102. return resp
  103. @esign_run_print_outer
  104. def seals_delete():
  105. """
  106. 删除个人印章
  107. :return:DELETE
  108. """
  109. psnId = "c7e00290541e7"
  110. sealId = "1caebb40***31f7f95087de"
  111. api_path = "/v3/seals/psn-seal?psnId={}&sealId={}".format(psnId, sealId) # 拼接请求路径
  112. print(api_path)
  113. method = esigntool.httpMethodEnum.DELETE # 声明请求方法
  114. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  115. method, api_path) # 签名并构造签名鉴权json请求头
  116. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  117. print(resp.text)
  118. return resp
  119. @esign_run_print_outer
  120. def create_sealsurl():
  121. """
  122. 获取创建个人印章页面链接
  123. :return:
  124. """
  125. # 构建请求body体
  126. body = {
  127. "psnId": "c7e002***0541e7",
  128. "sealName": "这是一个预定义印章名称",
  129. "customBizNum": "这是一串开发者内部系统自定义的编号",
  130. "redirectUrl": "https://www.xxx.cn/",
  131. "uneditableFields": ["sealName", "sealOpacity"],
  132. }
  133. api_path = "/v3/seals/psn-seal-create-url" # 拼接请求路径
  134. method = esigntool.httpMethodEnum.POST # 声明请求方法
  135. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  136. method, api_path, body) # 签名并构造签名鉴权json请求头
  137. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  138. print(resp.text)
  139. return resp
  140. @esign_run_print_outer
  141. def manage_sealsurl():
  142. """
  143. 获取管理个人印章页面链接
  144. :return:
  145. """
  146. # 构建请求body体
  147. body = {
  148. "psnId": "c7e002***0541e7"
  149. }
  150. api_path = "/v3/seals/psn-seals-manage-url" # 拼接请求路径
  151. method = esigntool.httpMethodEnum.POST # 声明请求方法
  152. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  153. method, api_path, body) # 签名并构造签名鉴权json请求头
  154. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  155. print(resp.text)
  156. return resp
  157. if __name__ == '__main__':
  158. createPsn_seals() # 创建个人模板印章
  159. create_image() # 创建个人图片印章
  160. seals_query() # 查询个人印章列表
  161. sealsinfo_query() # 查询指定印章详情
  162. change_seals() # 设置个人默认印章
  163. seals_delete() # 删除个人印章
  164. create_sealsurl() # 获取创建个人印章页面链接
  165. manage_sealsurl() # 获取管理个人印章页面链接