Skip to content

Commit cfb5327

Browse files
authored
🆕 #2644 【微信支付】新增微信支付银行组件模块
1 parent 6638383 commit cfb5327

File tree

9 files changed

+287
-1
lines changed

9 files changed

+287
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.github.binarywang.wxpay.bean.bank;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 对私银行卡号开户银行信息
13+
*
14+
* @author zhongjun
15+
**/
16+
@Data
17+
public class BankAccountResult implements Serializable {
18+
19+
private static final long serialVersionUID = -8226859146533243501L;
20+
21+
/**
22+
* 根据卡号查询到的银行列表数据的总条数,未查询到对应银行列表时默认返回0,最大不超过两百条。
23+
*/
24+
@SerializedName("total_count")
25+
private Integer totalCount;
26+
27+
@SerializedName("data")
28+
private List<BankInfo> data;
29+
30+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.github.binarywang.wxpay.bean.bank;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
8+
/**
9+
* 银行信息
10+
*
11+
* @author zhongjun
12+
* @date 2022/5/12
13+
**/
14+
@Data
15+
public class BankInfo {
16+
/**
17+
* 银行别名
18+
*/
19+
@SerializedName("bank_alias")
20+
private String bankAlias;
21+
/**
22+
* 银行别名编码
23+
*/
24+
@SerializedName("bank_alias_code")
25+
private String bankAliasCode;
26+
/**
27+
* 开户银行
28+
*/
29+
@SerializedName("account_bank")
30+
private String accountBank;
31+
/**
32+
* 开户银行编码
33+
*/
34+
@SerializedName("account_bank_code")
35+
private Integer accountBankCode;
36+
/**
37+
* 是否需要填写支行
38+
*/
39+
@SerializedName("need_bank_branch")
40+
private Boolean needBankBranch;
41+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.github.binarywang.wxpay.bean.bank;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 个人业务的银行列表
13+
*
14+
* @author zhongjun
15+
**/
16+
@Data
17+
public class BankingResult implements Serializable {
18+
private static final long serialVersionUID = -8372812998971715894L;
19+
20+
/**
21+
* 银行列表数据的总条数,调用方需要根据总条数分页查询
22+
*/
23+
@SerializedName("total_count")
24+
private Integer totalCount;
25+
26+
/**
27+
* 本次查询银行列表返回的数据条数
28+
*/
29+
@SerializedName("count")
30+
private Integer count;
31+
32+
/**
33+
* 该次请求资源的起始位置,请求中包含偏移量时应答消息返回相同偏移量,否则返回默认值0。
34+
*/
35+
@SerializedName("offset")
36+
private Integer offset;
37+
38+
@SerializedName("data")
39+
private List<BankInfo> data;
40+
41+
@SerializedName("links")
42+
private Link links;
43+
44+
@Getter
45+
@Setter
46+
public static class Link {
47+
/**
48+
* 下一页链接
49+
*/
50+
@SerializedName("next")
51+
private String next;
52+
/**
53+
* 上一页链接
54+
*/
55+
@SerializedName("prev")
56+
private String prev;
57+
/**
58+
* 当前链接
59+
*/
60+
@SerializedName("self")
61+
private String self;
62+
}
63+
64+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.github.binarywang.wxpay.service;
2+
3+
import com.github.binarywang.wxpay.bean.bank.BankAccountResult;
4+
import com.github.binarywang.wxpay.bean.bank.BankingResult;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
7+
/**
8+
* <pre>
9+
* 微信支付-银行组件
10+
* </pre>
11+
*
12+
* @author zhongjun
13+
**/
14+
public interface BankService {
15+
/**
16+
* <pre>
17+
*
18+
* 获取对私银行卡号开户银行
19+
*
20+
* 请求方式:GET(HTTPS)
21+
* 请求地址:<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>
22+
*
23+
* 文档地址:<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>
24+
* </pre>
25+
*
26+
* @param accountNumber 银行卡号 该字段需进行加密处理,加密方法详见敏感信息加密说明。(提醒:必须在HTTP头中上送Wechatpay-Serial)
27+
* @return BankAccountResult 对私银行卡号开户银行信息
28+
* @throws WxPayException .
29+
*/
30+
BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException;
31+
32+
/**
33+
* <pre>
34+
*
35+
* 查询支持个人业务的银行列表
36+
*
37+
* 请求方式:GET(HTTPS)
38+
* 请求地址:<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>
39+
*
40+
* 文档地址:<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>
41+
* </pre>
42+
*
43+
* @param offset 本次查询偏移量
44+
* @param limit 本次请求最大查询条数,最大值为200
45+
* @return PersonalBankingResult 支持个人业务的银行列表信息
46+
* @throws WxPayException .
47+
*/
48+
BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException;
49+
50+
/**
51+
* <pre>
52+
*
53+
* 支持对公业务的银行列表
54+
*
55+
* 请求方式:GET(HTTPS)
56+
* 请求地址:<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>
57+
*
58+
* 文档地址:<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>
59+
* </pre>
60+
*
61+
* @param offset 本次查询偏移量
62+
* @param limit 本次请求最大查询条数,最大值为200
63+
* @return BankingResult 支持对公业务的银行列表信息
64+
* @throws WxPayException .
65+
*/
66+
BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException;
67+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ public interface WxPayService {
164164
*/
165165
String getV3(String url) throws WxPayException;
166166

167+
/**
168+
* 发送get请求,得到响应字符串.
169+
* <p>
170+
* 部分字段会包含敏感信息,所以在提交前需要在请求头中会包含"Wechatpay-Serial"信息
171+
*
172+
* @param url 请求地址
173+
* @return 返回请求结果字符串 string
174+
* @throws WxPayException the wx pay exception
175+
*/
176+
String getV3WithWechatPaySerial(String url) throws WxPayException;
177+
167178
/**
168179
* 发送下载 V3请求,得到响应流.
169180
*
@@ -1337,4 +1348,11 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
13371348
* @return the complaints service
13381349
*/
13391350
ComplaintService getComplaintsService();
1351+
1352+
1353+
/**
1354+
* 获取银行组件服务
1355+
* @return 银行组件服务
1356+
*/
1357+
BankService getBankService();
13401358
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.github.binarywang.wxpay.service.impl;
2+
3+
import com.github.binarywang.wxpay.bean.bank.BankAccountResult;
4+
import com.github.binarywang.wxpay.bean.bank.BankingResult;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
import com.github.binarywang.wxpay.service.BankService;
7+
import com.github.binarywang.wxpay.service.WxPayService;
8+
import com.google.gson.Gson;
9+
import com.google.gson.GsonBuilder;
10+
import lombok.RequiredArgsConstructor;
11+
12+
/**
13+
* 微信支付-银行组件
14+
*
15+
* @author zhongjun
16+
**/
17+
@RequiredArgsConstructor
18+
public class BankServiceImpl implements BankService {
19+
private final WxPayService payService;
20+
private static final Gson GSON = new GsonBuilder().create();
21+
22+
@Override
23+
public BankAccountResult searchBanksByBankAccount(String accountNumber) throws WxPayException {
24+
String url = String.format("%s/v3/capital/capitallhh/banks/search-banks-by-bank-account?account_number=%s", this.payService.getPayBaseUrl(), accountNumber);
25+
String response = payService.getV3WithWechatPaySerial(url);
26+
return GSON.fromJson(response, BankAccountResult.class);
27+
}
28+
29+
@Override
30+
public BankingResult personalBanking(Integer offset, Integer limit) throws WxPayException {
31+
offset = offset == null ? 0 : offset;
32+
limit = limit == null ? 200 : limit;
33+
String url = String.format("%s/v3/capital/capitallhh/banks/personal-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit);
34+
String response = payService.getV3(url);
35+
return GSON.fromJson(response, BankingResult.class);
36+
}
37+
38+
@Override
39+
public BankingResult corporateBanking(Integer offset, Integer limit) throws WxPayException {
40+
offset = offset == null ? 0 : offset;
41+
limit = limit == null ? 200 : limit;
42+
String url = String.format("%s/v3/capital/capitallhh/banks/corporate-banking?offset=%s&limit=%s", this.payService.getPayBaseUrl(), offset, limit);
43+
String response = payService.getV3(url);
44+
return GSON.fromJson(response, BankingResult.class);
45+
}
46+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
7878
private final PartnerTransferService partnerTransferService = new PartnerTransferServiceImpl(this);
7979
private final PayrollService payrollService = new PayrollServiceImpl(this);
8080
private final ComplaintService complaintsService = new ComplaintServiceImpl(this);
81+
private final BankService bankService = new BankServiceImpl(this);
8182

8283
protected Map<String, WxPayConfig> configMap;
8384

@@ -1261,4 +1262,8 @@ public ComplaintService getComplaintsService() {
12611262
return complaintsService;
12621263
}
12631264

1265+
@Override
1266+
public BankService getBankService() {
1267+
return bankService;
1268+
}
12641269
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,17 @@ public String getV3(String url) throws WxPayException {
241241
HttpGet httpGet = new HttpGet(url);
242242
httpGet.addHeader("Accept", "application/json");
243243
httpGet.addHeader("Content-Type", "application/json");
244-
return this.requestV3(url.toString(), httpGet);
244+
return this.requestV3(url, httpGet);
245+
}
246+
247+
@Override
248+
public String getV3WithWechatPaySerial(String url) throws WxPayException {
249+
HttpGet httpGet = new HttpGet(url);
250+
httpGet.addHeader("Accept", "application/json");
251+
httpGet.addHeader("Content-Type", "application/json");
252+
String serialNumber = getConfig().getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase();
253+
httpGet.addHeader("Wechatpay-Serial", serialNumber);
254+
return this.requestV3(url, httpGet);
245255
}
246256

247257
@Override

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceJoddHttpImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public String getV3(String url) throws WxPayException {
9191
return null;
9292
}
9393

94+
@Override
95+
public String getV3WithWechatPaySerial(String url) throws WxPayException {
96+
return null;
97+
}
98+
9499
@Override
95100
public InputStream downloadV3(String url) throws WxPayException {
96101
return null;

0 commit comments

Comments
 (0)