order_query.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # 查询e签宝套餐余量
  8. @esign_run_print_outer
  9. def findOrderQuantity(orgId):
  10. """
  11. :param orgId:购买方企业账号
  12. :return:请求响应
  13. """
  14. api_path = "/v3/orders/remaining-quantity?orgId={}&distributor=true".format(orgId)
  15. method = esigntool.httpMethodEnum.GET
  16. if orgId == "":
  17. print("请设置实名企业账号ID")
  18. exit()
  19. # 签名并构造签名鉴权json请求头
  20. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, esigntool.apiPathSort(api_path))
  21. # 发起请求
  22. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers)
  23. print(resp.text)
  24. return resp.text
  25. # 查询e签宝套餐license
  26. @esign_run_print_outer
  27. def findOrderLicense(orgId):
  28. """
  29. :param orgId:购买方企业账号
  30. :return:请求响应
  31. """
  32. api_path = "/v1/mix/license/query"
  33. method = esigntool.httpMethodEnum.POST
  34. body = {
  35. "orgOid": orgId, # 机构账号ID(购买方orgId)
  36. "page": 1,
  37. "pageSize": 20
  38. }
  39. if orgId == "":
  40. print("请设置实名企业账号ID")
  41. exit()
  42. # 签名并构造签名鉴权json请求头
  43. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  44. # 发起请求
  45. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
  46. print(resp.text)
  47. return resp.text
  48. # 查询套餐订单列表
  49. @esign_run_print_outer
  50. def findOrderList(orgId):
  51. """
  52. :param orgId:购买方企业账号
  53. :return:请求响应
  54. """
  55. api_path = "/v3/orders/order-list?orgId={}&distributor=true".format(orgId)
  56. method = esigntool.httpMethodEnum.GET
  57. if orgId == "":
  58. print("请设置实名企业账号ID")
  59. exit()
  60. # 签名并构造签名鉴权json请求头
  61. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, esigntool.apiPathSort(api_path))
  62. # 发起请求
  63. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers)
  64. print(resp.text)
  65. return resp.text
  66. # 查询套餐订单列表(页面版)
  67. @esign_run_print_outer
  68. def getOrderListUrl(orgId, psnId):
  69. """
  70. :param orgId:购买方企业账号
  71. :param PsnId:购买方企业经办人账号
  72. :return:请求响应
  73. """
  74. api_path = "/v3/orders/org-order-manage-url"
  75. method = esigntool.httpMethodEnum.POST
  76. body = {
  77. "orgId": orgId, # 机构账号ID(购买方orgId)
  78. "transactorPsnId": psnId,
  79. "distributor": 'true'
  80. }
  81. if orgId == "" or psnId == "":
  82. print("请设置实名企业账号ID和经办人账号ID")
  83. exit()
  84. # 签名并构造签名鉴权json请求头
  85. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  86. # 发起请求
  87. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
  88. print(resp.text)
  89. return resp.text
  90. if __name__ == '__main__':
  91. if config.appId == "" or config.scert == "":
  92. print("请设置应用Appid和应用Secret")
  93. exit()
  94. orgId = "3236725******98cdf9f18d5" # 请输入实名企业帐号ID
  95. psnId = "12394U28935Y******T34Y3894" # 请输入实名个人帐号ID
  96. findOrderQuantity(orgId) # 查询e签宝套餐余量
  97. findOrderLicense(orgId) # 查询e签宝套餐license
  98. findOrderList(orgId) # 查询套餐订单列表
  99. getOrderListUrl(orgId, psnId) # 查询套餐订单列表(页面版)