order_demo.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # -*- coding: UTF-8 -*-
  2. import esigntool
  3. import requests
  4. from esigntool import esign_run_print_outer
  5. # EP订单场景:需要联系交付顾问协助配置商品信息,沙箱环境获取到商品购买链接后,可以购买测试套餐进行业务测试
  6. config = esigntool.config() # 初始化配置类
  7. @esign_run_print_outer
  8. def getBuyOrgOrderUrl(orgId,transactorPsnId):
  9. """
  10. 获取购买e签宝套餐链接
  11. :return:请求响应
  12. """
  13. api_path = "/v3/orders/org-place-order-url"
  14. method = esigntool.httpMethodEnum.POST
  15. body = {
  16. "orgId": orgId, # 机构账号ID(购买方orgId)
  17. "transactorPsnId": transactorPsnId, # 经办人个人账号ID(购买操作个人psnId)
  18. "redirectUrl": "https://www.baidu.com",
  19. "notifyUrl": "https://www.esign.cn/1",
  20. "customBizNum": "1111111" # 自定义编号
  21. }
  22. if orgId == "" or transactorPsnId == "":
  23. print("请设置企业账号ID和经办人账号ID")
  24. exit()
  25. # 签名并构造签名鉴权json请求头
  26. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  27. # 发起请求
  28. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
  29. print(resp.text)
  30. return resp.text
  31. @esign_run_print_outer
  32. def findOrderQuantity(orgId):
  33. """
  34. 查询e签宝套餐余量
  35. :return:请求响应
  36. """
  37. api_path = "/v3/orders/remaining-quantity?orgId={}&distributor=true".format(orgId)
  38. method = esigntool.httpMethodEnum.GET
  39. if orgId == "":
  40. print("请设置实名企业账号ID")
  41. exit()
  42. # 签名并构造签名鉴权json请求头
  43. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, esigntool.apiPathSort(api_path))
  44. # 发起请求
  45. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers)
  46. print(resp.text)
  47. return resp.text
  48. @esign_run_print_outer
  49. def findOrderList(orgId):
  50. """
  51. 查询套餐订单列表
  52. :return:请求响应
  53. """
  54. api_path = "/v3/orders/order-list?orgId={}&distributor=true".format(orgId)
  55. method = esigntool.httpMethodEnum.GET
  56. if orgId == "":
  57. print("请设置实名企业账号ID")
  58. exit()
  59. # 签名并构造签名鉴权json请求头
  60. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, esigntool.apiPathSort(api_path))
  61. # 发起请求
  62. resp = requests.request(method, config.host + api_path, json=None, headers=json_headers)
  63. print(resp.text)
  64. return resp.text
  65. @esign_run_print_outer
  66. def getOrderListUrl(orgId, transactorPsnId):
  67. """
  68. 查询套餐订单列表(页面版)
  69. :return:请求响应
  70. """
  71. api_path = "/v3/orders/org-order-manage-url"
  72. method = esigntool.httpMethodEnum.POST
  73. body = {
  74. "orgId": orgId, # 机构账号ID(购买方orgId)
  75. "transactorPsnId": transactorPsnId,
  76. "distributor": 'true'
  77. }
  78. if orgId == "" or transactorPsnId == "":
  79. print("请设置实名企业账号ID和经办人账号ID")
  80. exit()
  81. # 签名并构造签名鉴权json请求头
  82. json_headers = esigntool.buildSignJsonHeader(config.appId, config.scert, method, api_path, body=body)
  83. # 发起请求
  84. resp = requests.request(method, config.host + api_path, json=body, headers=json_headers)
  85. print(resp.text)
  86. return resp.text
  87. if __name__ == '__main__':
  88. orgId = "32367*********f9f18d5" # 购买方orgId,需要先通过实名接口,获取购买方企业orgId
  89. transactorPsnId = "2cc69e5*********ce1d3c" # 购买操作个人psnId,需要先通过实名接口,获取购买方企业psnId
  90. getBuyOrgOrderUrl(orgId, transactorPsnId) # 获取购买e签宝套餐链接
  91. findOrderQuantity(orgId) # 查询e签宝套餐余量
  92. findOrderList(orgId) # 查询套餐订单列表
  93. getOrderListUrl(orgId, transactorPsnId) # 查询套餐订单列表(页面版)