diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankAccountResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankAccountResult.java new file mode 100644 index 0000000000..5f67a2badf --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankAccountResult.java @@ -0,0 +1,30 @@ +package com.github.binarywang.wxpay.bean.bank; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.List; + +/** + * 对私银行卡号开户银行信息 + * + * @author zhongjun + **/ +@Data +public class BankAccountResult implements Serializable { + + private static final long serialVersionUID = -8226859146533243501L; + + /** + * 根据卡号查询到的银行列表数据的总条数,未查询到对应银行列表时默认返回0,最大不超过两百条。 + */ + @SerializedName("total_count") + private Integer totalCount; + + @SerializedName("data") + private List data; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankInfo.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankInfo.java new file mode 100644 index 0000000000..005963b875 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankInfo.java @@ -0,0 +1,41 @@ +package com.github.binarywang.wxpay.bean.bank; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +/** + * 银行信息 + * + * @author zhongjun + * @date 2022/5/12 + **/ +@Data +public class BankInfo { + /** + * 银行别名 + */ + @SerializedName("bank_alias") + private String bankAlias; + /** + * 银行别名编码 + */ + @SerializedName("bank_alias_code") + private String bankAliasCode; + /** + * 开户银行 + */ + @SerializedName("account_bank") + private String accountBank; + /** + * 开户银行编码 + */ + @SerializedName("account_bank_code") + private Integer accountBankCode; + /** + * 是否需要填写支行 + */ + @SerializedName("need_bank_branch") + private Boolean needBankBranch; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankingResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankingResult.java new file mode 100644 index 0000000000..407ad5fc55 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/bank/BankingResult.java @@ -0,0 +1,64 @@ +package com.github.binarywang.wxpay.bean.bank; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.List; + +/** + * 个人业务的银行列表 + * + * @author zhongjun + **/ +@Data +public class BankingResult implements Serializable { + private static final long serialVersionUID = -8372812998971715894L; + + /** + * 银行列表数据的总条数,调用方需要根据总条数分页查询 + */ + @SerializedName("total_count") + private Integer totalCount; + + /** + * 本次查询银行列表返回的数据条数 + */ + @SerializedName("count") + private Integer count; + + /** + * 该次请求资源的起始位置,请求中包含偏移量时应答消息返回相同偏移量,否则返回默认值0。 + */ + @SerializedName("offset") + private Integer offset; + + @SerializedName("data") + private List data; + + @SerializedName("links") + private Link links; + + @Getter + @Setter + public static class Link { + /** + * 下一页链接 + */ + @SerializedName("next") + private String next; + /** + * 上一页链接 + */ + @SerializedName("prev") + private String prev; + /** + * 当前链接 + */ + @SerializedName("self") + private String self; + } + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BankService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BankService.java new file mode 100644 index 0000000000..e08b9fb524 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/BankService.java @@ -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; + +/** + *
+ * 微信支付-银行组件
+ * 
+ * + * @author zhongjun + **/ +public interface BankService { + /** + *
+   *
+   * 获取对私银行卡号开户银行
+   *
+   * 请求方式:GET(HTTPS)
+   * 请求地址:https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/search-banks-by-bank-account
+   *
+   * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_1.shtml
+   * 
+ * + * @param accountNumber 银行卡号 该字段需进行加密处理,加密方法详见敏感信息加密说明。(提醒:必须在HTTP头中上送Wechatpay-Serial) + * @return BankAccountResult 对私银行卡号开户银行信息 + * @throws WxPayException . + */ + BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException; + + /** + *
+   *
+   * 查询支持个人业务的银行列表
+   *
+   * 请求方式:GET(HTTPS)
+   * 请求地址:https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/personal-banking
+   *
+   * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_2.shtml
+   * 
+ * + * @param offset 本次查询偏移量 + * @param limit 本次请求最大查询条数,最大值为200 + * @return PersonalBankingResult 支持个人业务的银行列表信息 + * @throws WxPayException . + */ + BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException; + + /** + *
+   *
+   * 支持对公业务的银行列表
+   *
+   * 请求方式:GET(HTTPS)
+   * 请求地址:https://api.mch.weixin.qq.com/v3/capital/capitallhh/banks/corporate-banking
+   *
+   * 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter11_2_3.shtml
+   * 
+ * + * @param offset 本次查询偏移量 + * @param limit 本次请求最大查询条数,最大值为200 + * @return BankingResult 支持对公业务的银行列表信息 + * @throws WxPayException . + */ + BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException; +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index 5afabbb3d3..74f353e838 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -164,6 +164,17 @@ public interface WxPayService { */ String getV3(String url) throws WxPayException; + /** + * 发送get请求,得到响应字符串. + *

+ * 部分字段会包含敏感信息,所以在提交前需要在请求头中会包含"Wechatpay-Serial"信息 + * + * @param url 请求地址 + * @return 返回请求结果字符串 string + * @throws WxPayException the wx pay exception + */ + String getV3WithWechatPaySerial(String url) throws WxPayException; + /** * 发送下载 V3请求,得到响应流. * @@ -1337,4 +1348,11 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri * @return the complaints service */ ComplaintService getComplaintsService(); + + + /** + * 获取银行组件服务 + * @return 银行组件服务 + */ + BankService getBankService(); } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BankServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BankServiceImpl.java new file mode 100644 index 0000000000..58739b5fd2 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BankServiceImpl.java @@ -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); + } +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index 128a7362dd..ecce6c62f6 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -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 configMap; @@ -1261,4 +1262,8 @@ public ComplaintService getComplaintsService() { return complaintsService; } + @Override + public BankService getBankService() { + return bankService; + } } diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java index e70813fc37..47f78c88e9 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java @@ -241,7 +241,17 @@ public String getV3(String url) throws WxPayException { 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 diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java index 29521d493a..5e6d23eac9 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java @@ -91,6 +91,11 @@ public String getV3(String url) throws WxPayException { return null; } + @Override + public String getV3WithWechatPaySerial(String url) throws WxPayException { + return null; + } + @Override public InputStream downloadV3(String url) throws WxPayException { return null;