support.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. from library.jdbase.exceptions import JDException
  4. from library.jdopen.client.api.base import BaseJdOpenAPI
  5. class JdOpenSupport(BaseJdOpenAPI):
  6. def query_province(self):
  7. """
  8. 查询省
  9. """
  10. return self._get("/v1/agent/province/list")
  11. def query_city(self, code):
  12. """
  13. 查询市
  14. """
  15. return self._get("/v1/agent/city/list/code/{code}".format(code = code))
  16. def query_district(self, code):
  17. """
  18. 查询区
  19. """
  20. return self._get("/v1/agent/district/list/code/{code}".format(code = code))
  21. def query_industry(self):
  22. """
  23. 查询一级行业
  24. """
  25. return self._get("/v1/agent/industry/list")
  26. def query_sub_industry(self, num):
  27. """
  28. 查询二级行业
  29. """
  30. return self._get("/v1/agent/industry/second/list/code/{num}".format(num = num))
  31. def query_bank(self, k = None):
  32. """
  33. 查询银行
  34. """
  35. return self._get("/v1/agent/bank/list/{k}".format(k = k or u"银行"))
  36. def query_sub_bank(self, bankCode, subK = None):
  37. """
  38. 查询支行
  39. """
  40. return self._get(
  41. "/v1/agent/bankSub/list/{bankCode}/{subK}".format(bankCode = bankCode or u"", subK = subK or u"行"))
  42. def query_pay_type(self):
  43. return self._get("/v1/agent/pay/bankinfo/list")
  44. def get_product_customer(self, customerNum, payProduct):
  45. url = "/api/queryTradeRoute"
  46. data = {
  47. "customerNum": customerNum,
  48. "payProduct": payProduct
  49. }
  50. return self._post(url = url, data = data)
  51. def query_sub_channel(self, customerNum, payProduct):
  52. payProduct = payProduct if payProduct else "WX"
  53. result = self.get_product_customer(customerNum, payProduct)
  54. if not result or 'data' not in result:
  55. return None
  56. for item in result["data"]:
  57. if item["status"] == "OPEN":
  58. return item["subCustomerNum"]
  59. return None
  60. def query_auth_status(self, customerNum, payProduct, subMerchantId):
  61. def processor(self, result):
  62. if 'success' not in result or not result['success'] or result['code'] != 'success':
  63. raise JDException(
  64. errCode = result.get('code'),
  65. errMsg = result.get("message"),
  66. client = self)
  67. else:
  68. return result
  69. url = "/api/queryAuthStatus"
  70. data = {
  71. 'agentNum': self.agentNum,
  72. 'customerNum': customerNum,
  73. 'bankType': payProduct,
  74. 'subCustomerNum': subMerchantId
  75. }
  76. sendData = {_k: str(_v) for _k, _v in data.items() if _v is not None}
  77. return self._post(url = url, data = sendData, processor = processor)
  78. def submit_auth(self, customerNum, payProduct, subMerchantId):
  79. def processor(self, result):
  80. if 'success' not in result or not result['success'] or result['code'] != 'success':
  81. raise JDException(
  82. errCode = result.get('code'),
  83. errMsg = result.get("message"),
  84. client = self)
  85. else:
  86. return result
  87. url = "/api/wxCreateAuthorizeInfo"
  88. data = {
  89. 'agentNum': self.agentNum,
  90. 'customerNum': customerNum,
  91. 'bankType': payProduct,
  92. 'subCustomerNum': subMerchantId
  93. }
  94. sendData = {_k: str(_v) for _k, _v in data.items() if _v is not None}
  95. return self._post(url = url, data = sendData, processor = processor)
  96. def add_wechat_auth_pay_dir(self, customerNum, auth_pay_dir):
  97. """
  98. 追加商户微信支付目录
  99. :param customerNum:
  100. :param auth_pay_dir:
  101. :return:
  102. """
  103. def processor(self, result):
  104. if 'success' not in result or not result['success'] or result['code'] != 'success':
  105. raise JDException(
  106. errCode = result.get('code'),
  107. errMsg = result.get("message"),
  108. client = self)
  109. else:
  110. return result
  111. url = '/api/addAuthPayDirsDevConfig'
  112. data = {
  113. 'customerNum': customerNum,
  114. 'authPayDir': auth_pay_dir
  115. }
  116. return self._post(url = url, data = data, processor = processor)
  117. def query_wechat_auth_pay_dir(self, customerNum, batchNum):
  118. """
  119. 查询商户微信支付目录
  120. :param customerNum:
  121. :param auth_pay_dir:
  122. :return:
  123. """
  124. def processor(self, result):
  125. if 'success' not in result or not result['success'] or result['code'] != 'success':
  126. raise JDException(
  127. errCode = result.get('code'),
  128. errMsg = result.get("message"),
  129. client = self)
  130. else:
  131. return result
  132. url = '/api/queryAddAuthPayDirsDevConfigByBatchNum'
  133. data = {
  134. 'customerNum': customerNum,
  135. 'batchNum': batchNum
  136. }
  137. return self._post(url = url, data = data, processor = processor)