Skip to content

Commit

Permalink
🆕 #2644 【微信支付】新增微信支付银行组件模块
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongjun96 authored May 15, 2022
1 parent 6638383 commit cfb5327
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<BankInfo> data;

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<BankInfo> 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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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请求,得到响应流.
*
Expand Down Expand Up @@ -1337,4 +1348,11 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
* @return the complaints service
*/
ComplaintService getComplaintsService();


/**
* 获取银行组件服务
* @return 银行组件服务
*/
BankService getBankService();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1261,4 +1262,8 @@ public ComplaintService getComplaintsService() {
return complaintsService;
}

@Override
public BankService getBankService() {
return bankService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cfb5327

Please sign in to comment.