# -*- coding: utf-8 -*- # !/usr/bin/env python from library.jdbase.exceptions import JDException from library.jdopen.client.api.base import BaseJdOpenAPI class JdOpenSupport(BaseJdOpenAPI): def query_province(self): """ 查询省 """ return self._get("/v1/agent/province/list") def query_city(self, code): """ 查询市 """ return self._get("/v1/agent/city/list/code/{code}".format(code = code)) def query_district(self, code): """ 查询区 """ return self._get("/v1/agent/district/list/code/{code}".format(code = code)) def query_industry(self): """ 查询一级行业 """ return self._get("/v1/agent/industry/list") def query_sub_industry(self, num): """ 查询二级行业 """ return self._get("/v1/agent/industry/second/list/code/{num}".format(num = num)) def query_bank(self, k = None): """ 查询银行 """ return self._get("/v1/agent/bank/list/{k}".format(k = k or u"银行")) def query_sub_bank(self, bankCode, subK = None): """ 查询支行 """ return self._get( "/v1/agent/bankSub/list/{bankCode}/{subK}".format(bankCode = bankCode or u"", subK = subK or u"行")) def query_pay_type(self): return self._get("/v1/agent/pay/bankinfo/list") def get_product_customer(self, customerNum, payProduct): url = "/api/queryTradeRoute" data = { "customerNum": customerNum, "payProduct": payProduct } return self._post(url = url, data = data) def query_sub_channel(self, customerNum, payProduct): payProduct = payProduct if payProduct else "WX" result = self.get_product_customer(customerNum, payProduct) if not result or 'data' not in result: return None for item in result["data"]: if item["status"] == "OPEN": return item["subCustomerNum"] return None def query_auth_status(self, customerNum, payProduct, subMerchantId): def processor(self, result): if 'success' not in result or not result['success'] or result['code'] != 'success': raise JDException( errCode = result.get('code'), errMsg = result.get("message"), client = self) else: return result url = "/api/queryAuthStatus" data = { 'agentNum': self.agentNum, 'customerNum': customerNum, 'bankType': payProduct, 'subCustomerNum': subMerchantId } sendData = {_k: str(_v) for _k, _v in data.items() if _v is not None} return self._post(url = url, data = sendData, processor = processor) def submit_auth(self, customerNum, payProduct, subMerchantId): def processor(self, result): if 'success' not in result or not result['success'] or result['code'] != 'success': raise JDException( errCode = result.get('code'), errMsg = result.get("message"), client = self) else: return result url = "/api/wxCreateAuthorizeInfo" data = { 'agentNum': self.agentNum, 'customerNum': customerNum, 'bankType': payProduct, 'subCustomerNum': subMerchantId } sendData = {_k: str(_v) for _k, _v in data.items() if _v is not None} return self._post(url = url, data = sendData, processor = processor) def add_wechat_auth_pay_dir(self, customerNum, auth_pay_dir): """ 追加商户微信支付目录 :param customerNum: :param auth_pay_dir: :return: """ def processor(self, result): if 'success' not in result or not result['success'] or result['code'] != 'success': raise JDException( errCode = result.get('code'), errMsg = result.get("message"), client = self) else: return result url = '/api/addAuthPayDirsDevConfig' data = { 'customerNum': customerNum, 'authPayDir': auth_pay_dir } return self._post(url = url, data = data, processor = processor) def query_wechat_auth_pay_dir(self, customerNum, batchNum): """ 查询商户微信支付目录 :param customerNum: :param auth_pay_dir: :return: """ def processor(self, result): if 'success' not in result or not result['success'] or result['code'] != 'success': raise JDException( errCode = result.get('code'), errMsg = result.get("message"), client = self) else: return result url = '/api/queryAddAuthPayDirsDevConfigByBatchNum' data = { 'customerNum': customerNum, 'batchNum': batchNum } return self._post(url = url, data = data, processor = processor)