Skip to content

Commit 0640c10

Browse files
authored
🆕 binarywang#3023 【微信支付】增加根据账户类型查询二级商户实时余额的接口,同时修复批量转账订单相关接口的问题
1 parent 1583aaf commit 0640c10

4 files changed

Lines changed: 43 additions & 12 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ public interface EcommerceService {
215215
*/
216216
FundBalanceResult subNowBalance(String subMchid) throws WxPayException;
217217

218+
/**
219+
* <pre>
220+
* 二级商户号账户实时余额
221+
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter4_3_11.shtml
222+
* </pre>
223+
*
224+
* @param subMchid 二级商户号
225+
* @param accountType 账户类型
226+
* @return 返回数据 fund balance result
227+
* @throws WxPayException the wx pay exception
228+
*/
229+
FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException;
230+
218231
/**
219232
* <pre>
220233
* 二级商户号账户日终余额

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
import java.nio.charset.StandardCharsets;
2727
import java.security.GeneralSecurityException;
2828
import java.text.DateFormat;
29-
import java.util.Iterator;
30-
import java.util.Map;
31-
import java.util.LinkedHashMap;
32-
import java.util.Objects;
33-
import java.util.Set;
29+
import java.util.*;
3430

3531
@RequiredArgsConstructor
3632
public class EcommerceServiceImpl implements EcommerceService {
@@ -188,6 +184,16 @@ public FundBalanceResult subNowBalance(String subMchid) throws WxPayException {
188184
return GSON.fromJson(response, FundBalanceResult.class);
189185
}
190186

187+
@Override
188+
public FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException {
189+
String url = String.format("%s/v3/ecommerce/fund/balance/%s", this.payService.getPayBaseUrl(), subMchid);
190+
if (Objects.nonNull(accountType)) {
191+
url += "?account_type=" + accountType.getValue();
192+
}
193+
String response = this.payService.getV3(url);
194+
return GSON.fromJson(response, FundBalanceResult.class);
195+
}
196+
191197
@Override
192198
public FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException {
193199
String url = String.format("%s/v3/ecommerce/fund/enddaybalance/%s?date=%s", this.payService.getPayBaseUrl(), subMchid, date);

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,19 @@ public class PartnerTransferServiceImpl implements PartnerTransferService {
4343
*/
4444
@Override
4545
public PartnerTransferResult batchTransfer(PartnerTransferRequest request) throws WxPayException {
46-
request.getTransferDetailList().stream().forEach(p -> {
46+
request.getTransferDetailList().forEach(p -> {
4747
try {
4848
String userName = RsaCryptoUtil.encryptOAEP(p.getUserName(),
4949
this.payService.getConfig().getVerifier().getValidCertificate());
5050
p.setUserName(userName);
51+
52+
if (StringUtil.isNotBlank(p.getUserIdCard())) {
53+
String userIdCard = RsaCryptoUtil.encryptOAEP(p.getUserIdCard(),
54+
this.payService.getConfig().getVerifier().getValidCertificate());
55+
p.setUserIdCard(userIdCard);
56+
}
5157
} catch (IllegalBlockSizeException e) {
52-
throw new RuntimeException("姓名转换异常!", e);
58+
throw new RuntimeException("姓名或身份证转换异常!", e);
5359
}
5460
});
5561
String url = String.format("%s/v3/partner-transfer/batches", this.payService.getPayBaseUrl());
@@ -81,11 +87,10 @@ public BatchNumberResult queryBatchByBatchId(BatchNumberRequest request) throws
8187
if (request.getLimit() == null || request.getLimit() <= 0) {
8288
request.setLimit(20);
8389
}
84-
String query = String.format("?need_query_detail=%s&detail_status=ALL&offset=%s&limit=%s",
85-
request.getNeedQueryDetail(), request.getOffset(), request.getLimit());
86-
if (StringUtil.isNotBlank(request.getDetailStatus())) {
87-
query += "&detail_status=" + request.getDetailStatus();
88-
}
90+
String detailStatus = StringUtil.isNotBlank(request.getDetailStatus()) ? request.getDetailStatus() : "ALL";
91+
92+
String query = String.format("?need_query_detail=%s&detail_status=%s&offset=%s&limit=%s",
93+
request.getNeedQueryDetail(), detailStatus, request.getOffset(), request.getLimit());
8994
String response = this.payService.getV3(url + query);
9095
return GSON.fromJson(response, BatchNumberResult.class);
9196
}

weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingReceiverResult;
88
import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
99
import com.github.binarywang.wxpay.bean.ecommerce.TransactionsResult;
10+
import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum;
1011
import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
1112
import com.github.binarywang.wxpay.exception.WxPayException;
1213
import com.github.binarywang.wxpay.service.WxPayService;
@@ -125,6 +126,12 @@ public void testSubNowBalance() throws WxPayException {
125126
wxPayService.getEcommerceService().subNowBalance(subMchid);
126127
}
127128

129+
@Test
130+
public void testSubNowBalanceWithAccountType() throws WxPayException {
131+
String subMchid = "";
132+
wxPayService.getEcommerceService().subNowBalance(subMchid, SpAccountTypeEnum.BASIC);
133+
}
134+
128135
@Test
129136
public void testAddReceivers() throws WxPayException {
130137
ProfitSharingReceiverRequest request = new ProfitSharingReceiverRequest();

0 commit comments

Comments
 (0)