Browse Source

:new: #3023 【微信支付】增加根据账户类型查询二级商户实时余额的接口,同时修复批量转账订单相关接口的问题

wincham 1 year ago
parent
commit
0640c10671

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

@@ -217,6 +217,19 @@ public interface EcommerceService {
 
   /**
    * <pre>
+   * 二级商户号账户实时余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter4_3_11.shtml
+   * </pre>
+   *
+   * @param subMchid 二级商户号
+   * @param accountType 账户类型
+   * @return 返回数据 fund balance result
+   * @throws WxPayException the wx pay exception
+   */
+  FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException;
+
+  /**
+   * <pre>
    * 二级商户号账户日终余额
    * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/amount.shtml
    * </pre>

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

@@ -26,11 +26,7 @@ import java.lang.reflect.Method;
 import java.nio.charset.StandardCharsets;
 import java.security.GeneralSecurityException;
 import java.text.DateFormat;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.LinkedHashMap;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
 
 @RequiredArgsConstructor
 public class EcommerceServiceImpl implements EcommerceService {
@@ -189,6 +185,16 @@ public class EcommerceServiceImpl implements EcommerceService {
   }
 
   @Override
+  public FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException {
+    String url = String.format("%s/v3/ecommerce/fund/balance/%s", this.payService.getPayBaseUrl(), subMchid);
+    if (Objects.nonNull(accountType)) {
+      url += "?account_type=" + accountType.getValue();
+    }
+    String response = this.payService.getV3(url);
+    return GSON.fromJson(response, FundBalanceResult.class);
+  }
+
+  @Override
   public FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException {
     String url = String.format("%s/v3/ecommerce/fund/enddaybalance/%s?date=%s", this.payService.getPayBaseUrl(), subMchid, date);
     String response = this.payService.getV3(url);

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

@@ -43,13 +43,19 @@ public class PartnerTransferServiceImpl implements PartnerTransferService {
    */
   @Override
   public PartnerTransferResult batchTransfer(PartnerTransferRequest request) throws WxPayException {
-    request.getTransferDetailList().stream().forEach(p -> {
+    request.getTransferDetailList().forEach(p -> {
       try {
         String userName = RsaCryptoUtil.encryptOAEP(p.getUserName(),
           this.payService.getConfig().getVerifier().getValidCertificate());
         p.setUserName(userName);
+
+        if (StringUtil.isNotBlank(p.getUserIdCard())) {
+          String userIdCard = RsaCryptoUtil.encryptOAEP(p.getUserIdCard(),
+            this.payService.getConfig().getVerifier().getValidCertificate());
+          p.setUserIdCard(userIdCard);
+        }
       } catch (IllegalBlockSizeException e) {
-        throw new RuntimeException("姓名转换异常!", e);
+        throw new RuntimeException("姓名或身份证转换异常!", e);
       }
     });
     String url = String.format("%s/v3/partner-transfer/batches", this.payService.getPayBaseUrl());
@@ -81,11 +87,10 @@ public class PartnerTransferServiceImpl implements PartnerTransferService {
     if (request.getLimit() == null || request.getLimit() <= 0) {
       request.setLimit(20);
     }
-    String query = String.format("?need_query_detail=%s&detail_status=ALL&offset=%s&limit=%s",
-      request.getNeedQueryDetail(), request.getOffset(), request.getLimit());
-    if (StringUtil.isNotBlank(request.getDetailStatus())) {
-      query += "&detail_status=" + request.getDetailStatus();
-    }
+    String detailStatus = StringUtil.isNotBlank(request.getDetailStatus()) ? request.getDetailStatus() : "ALL";
+
+    String query = String.format("?need_query_detail=%s&detail_status=%s&offset=%s&limit=%s",
+      request.getNeedQueryDetail(), detailStatus, request.getOffset(), request.getLimit());
     String response = this.payService.getV3(url + query);
     return GSON.fromJson(response, BatchNumberResult.class);
   }

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

@@ -7,6 +7,7 @@ import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingReceiverRequest;
 import com.github.binarywang.wxpay.bean.ecommerce.ProfitSharingReceiverResult;
 import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader;
 import com.github.binarywang.wxpay.bean.ecommerce.TransactionsResult;
+import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum;
 import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
@@ -126,6 +127,12 @@ public class EcommerceServiceImplTest {
   }
 
   @Test
+  public void testSubNowBalanceWithAccountType() throws WxPayException {
+    String subMchid = "";
+    wxPayService.getEcommerceService().subNowBalance(subMchid, SpAccountTypeEnum.BASIC);
+  }
+
+  @Test
   public void testAddReceivers() throws WxPayException {
     ProfitSharingReceiverRequest request = new ProfitSharingReceiverRequest();
     request.setAppid("wx8888888888888888");