-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(微信支付):新增微信支付银行组件模块 #2644
feat(微信支付):新增微信支付银行组件模块 #2644
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
---|---|---|
|
@@ -241,7 +241,17 @@ public String getV3(String url) throws WxPayException { | |
HttpGet httpGet = new HttpGet(url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTP_PARAMETER_POLLUTION: Concatenating user-controlled input into a URL (at-me in a reply with Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTTP_PARAMETER_POLLUTION: Concatenating user-controlled input into a URL (at-me in a reply with Was this a good recommendation? |
||
httpGet.addHeader("Accept", "application/json"); | ||
httpGet.addHeader("Content-Type", "application/json"); | ||
String serialNumber = getConfig().getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NULL_DEREFERENCE: object returned by (at-me in a reply with Was this a good recommendation? |
||
httpGet.addHeader("Wechatpay-Serial", serialNumber); | ||
return this.requestV3(url, httpGet); | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SameNameButDifferent: The name
@RequiredArgsConstructor
refers to [java.lang.SuppressWarnings, com.github.binarywang.wxpay.service.WxPayService] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.(at-me in a reply with
help
orignore
)Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]