org_member.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 create_templateseals():
  8. """
  9. 添加企业机构成员
  10. :return:
  11. """
  12. # 构建请求body体
  13. body = {
  14. "members": [
  15. {
  16. "psnId": "d3fcf19***0ddc60a13",
  17. "memberName": "成员1的姓名",
  18. "employeeNum": "100"
  19. },
  20. {
  21. "psnId": "501a277***6b19b7211",
  22. "memberName": "成员2的姓名",
  23. "employeeNum": "101"
  24. }
  25. ]
  26. }
  27. orgId = "501a277***6b19b7211"
  28. api_path = "/v3/organizations/{}/members".format(orgId) # 拼接请求路径
  29. method = esigntool.httpMethodEnum.POST # 声明请求方法
  30. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  31. method, api_path, body) # 签名并构造签名鉴权json请求头
  32. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  33. print(resp.text)
  34. return resp
  35. @esign_run_print_outer
  36. def members_delete():
  37. """
  38. 移除企业机构成员
  39. :return:DELETE
  40. """
  41. # 构建请求body体
  42. body = {
  43. "memberPsnIds": ['d3fcf1b***dc60a13', '8d28bfe***23b135f']
  44. }
  45. orgId = "c7e00*****541e7"
  46. api_path = "/v3/organizations/{}/members".format(orgId) # 拼接请求路径
  47. print(api_path)
  48. method = esigntool.httpMethodEnum.DELETE # 声明请求方法
  49. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  50. method, api_path, body) # 签名并构造签名鉴权json请求头
  51. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers) # 发送请求
  52. print(resp.text)
  53. return resp
  54. @esign_run_print_outer
  55. def member_list():
  56. """
  57. 查询企业机构成员
  58. :return:
  59. """
  60. orgId = "11"
  61. pageNum = "11"
  62. pageSize = "22"
  63. api_path = "/v3/organizations/{}/member-list?pageNum={}&pageSize={}".format(orgId, pageNum,
  64. pageSize) # 拼接请求路径
  65. method = esigntool.httpMethodEnum.GET # 声明请求方法
  66. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert,
  67. method, api_path) # 签名并构造签名鉴权json请求头
  68. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers) # 发送请求
  69. print(resp.text)
  70. return resp
  71. @esign_run_print_outer
  72. def administrators():
  73. """
  74. 查询企业机构管理员
  75. :return:
  76. """
  77. orgId = "11"
  78. api_path = "/v3/organizations/{}/administrators".format(orgId) # 拼接请求路径
  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. if __name__ == '__main__':
  86. create_templateseals() # 添加企业机构成员
  87. members_delete() # 移除企业机构成员
  88. member_list() # 查询企业机构成员
  89. administrators() # 查询企业机构管理员