mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🆕 #2644 【微信支付】新增微信支付银行组件模块
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.github.binarywang.wxpay.service;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.bank.BankAccountResult;
|
||||
import com.github.binarywang.wxpay.bean.bank.BankingResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信支付-银行组件
|
||||
* </pre>
|
||||
*
|
||||
* @author zhongjun
|
||||
**/
|
||||
public interface BankService {
|
||||
/**
|
||||
* <pre>
|
||||
*
|
||||
* 获取对私银行卡号开户银行
|
||||
*
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/search-banks-by-bank-account">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/search-banks-by-bank-account</a>
|
||||
*
|
||||
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param accountNumber 银行卡号 该字段需进行加密处理,加密方法详见敏感信息加密说明。(提醒:必须在HTTP头中上送Wechatpay-Serial)
|
||||
* @return BankAccountResult 对私银行卡号开户银行信息
|
||||
* @throws WxPayException .
|
||||
*/
|
||||
BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
*
|
||||
* 查询支持个人业务的银行列表
|
||||
*
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/personal-banking">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/personal-banking</a>
|
||||
*
|
||||
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param offset 本次查询偏移量
|
||||
* @param limit 本次请求最大查询条数,最大值为200
|
||||
* @return PersonalBankingResult 支持个人业务的银行列表信息
|
||||
* @throws WxPayException .
|
||||
*/
|
||||
BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
*
|
||||
* 支持对公业务的银行列表
|
||||
*
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/corporate-banking">https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/corporate-banking</a>
|
||||
*
|
||||
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml">https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml</a>
|
||||
* </pre>
|
||||
*
|
||||
* @param offset 本次查询偏移量
|
||||
* @param limit 本次请求最大查询条数,最大值为200
|
||||
* @return BankingResult 支持对公业务的银行列表信息
|
||||
* @throws WxPayException .
|
||||
*/
|
||||
BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException;
|
||||
}
|
||||
@@ -164,6 +164,17 @@ public interface WxPayService {
|
||||
*/
|
||||
String getV3(String url) throws WxPayException;
|
||||
|
||||
/**
|
||||
* 发送get请求,得到响应字符串.
|
||||
* <p>
|
||||
* 部分字段会包含敏感信息,所以在提交前需要在请求头中会包含"Wechatpay-Serial"信息
|
||||
*
|
||||
* @param url 请求地址
|
||||
* @return 返回请求结果字符串 string
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
String getV3WithWechatPaySerial(String url) throws WxPayException;
|
||||
|
||||
/**
|
||||
* 发送下载 V3请求,得到响应流.
|
||||
*
|
||||
@@ -1337,4 +1348,11 @@ public interface WxPayService {
|
||||
* @return the complaints service
|
||||
*/
|
||||
ComplaintService getComplaintsService();
|
||||
|
||||
|
||||
/**
|
||||
* 获取银行组件服务
|
||||
* @return 银行组件服务
|
||||
*/
|
||||
BankService getBankService();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.github.binarywang.wxpay.service.impl;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.bank.BankAccountResult;
|
||||
import com.github.binarywang.wxpay.bean.bank.BankingResult;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.BankService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 微信支付-银行组件
|
||||
*
|
||||
* @author zhongjun
|
||||
**/
|
||||
@RequiredArgsConstructor
|
||||
public class BankServiceImpl implements BankService {
|
||||
private final WxPayService payService;
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
@Override
|
||||
public BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException {
|
||||
String url = String.format("%s/v3/capital/capitallhh/banks/search-banks-by-bank-account?account_number=%s", this.payService.getPayBaseUrl(), accountNumber);
|
||||
String response = payService.getV3WithWechatPaySerial(url);
|
||||
return GSON.fromJson(response, BankAccountResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException {
|
||||
offset = offset == null ? 0 : offset;
|
||||
limit = limit == null ? 200 : limit;
|
||||
String url = String.format("%s/v3/capital/capitallhh/banks/personal-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit);
|
||||
String response = payService.getV3(url);
|
||||
return GSON.fromJson(response, BankingResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException {
|
||||
offset = offset == null ? 0 : offset;
|
||||
limit = limit == null ? 200 : limit;
|
||||
String url = String.format("%s/v3/capital/capitallhh/banks/corporate-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit);
|
||||
String response = payService.getV3(url);
|
||||
return GSON.fromJson(response, BankingResult.class);
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
private final PartnerTransferService partnerTransferService = new PartnerTransferServiceImpl(this);
|
||||
private final PayrollService payrollService = new PayrollServiceImpl(this);
|
||||
private final ComplaintService complaintsService = new ComplaintServiceImpl(this);
|
||||
private final BankService bankService = new BankServiceImpl(this);
|
||||
|
||||
protected Map<String, WxPayConfig> configMap;
|
||||
|
||||
@@ -1261,4 +1262,8 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
||||
return complaintsService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BankService getBankService() {
|
||||
return bankService;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,17 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
httpGet.addHeader("Accept", "application/json");
|
||||
httpGet.addHeader("Content-Type", "application/json");
|
||||
return this.requestV3(url.toString(), httpGet);
|
||||
return this.requestV3(url, httpGet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getV3WithWechatPaySerial(String url) throws WxPayException {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
httpGet.addHeader("Accept", "application/json");
|
||||
httpGet.addHeader("Content-Type", "application/json");
|
||||
String serialNumber = getConfig().getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase();
|
||||
httpGet.addHeader("Wechatpay-Serial", serialNumber);
|
||||
return this.requestV3(url, httpGet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -91,6 +91,11 @@ public class WxPayServiceJoddHttpImpl extends BaseWxPayServiceImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getV3WithWechatPaySerial(String url) throws WxPayException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream downloadV3(String url) throws WxPayException {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user