From 0640c1067194ff73d9ce6f8cfb15c8f1c8b3834f Mon Sep 17 00:00:00 2001 From: wincham Date: Wed, 31 May 2023 16:28:18 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#3023=20=E3=80=90=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E3=80=91=E5=A2=9E=E5=8A=A0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E7=B1=BB=E5=9E=8B=E6=9F=A5=E8=AF=A2=E4=BA=8C?= =?UTF-8?q?=E7=BA=A7=E5=95=86=E6=88=B7=E5=AE=9E=E6=97=B6=E4=BD=99=E9=A2=9D?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=90=8C=E6=97=B6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=89=B9=E9=87=8F=E8=BD=AC=E8=B4=A6=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxpay/service/EcommerceService.java | 13 +++++++++++++ .../service/impl/EcommerceServiceImpl.java | 16 +++++++++++----- .../impl/PartnerTransferServiceImpl.java | 19 ++++++++++++------- .../impl/EcommerceServiceImplTest.java | 7 +++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java index c8d94acd4..5b2a8beae 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java @@ -215,6 +215,19 @@ public interface EcommerceService { */ FundBalanceResult subNowBalance(String subMchid) throws WxPayException; + /** + *
+   * 二级商户号账户实时余额
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter4_3_11.shtml
+   * 
+ * + * @param subMchid 二级商户号 + * @param accountType 账户类型 + * @return 返回数据 fund balance result + * @throws WxPayException the wx pay exception + */ + FundBalanceResult subNowBalance(String subMchid, SpAccountTypeEnum accountType) throws WxPayException; + /** *
    * 二级商户号账户日终余额
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java
index 27a34a9e2..3d9a1af62 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java
+++ b/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 {
@@ -188,6 +184,16 @@ public class EcommerceServiceImpl implements EcommerceService {
     return GSON.fromJson(response, FundBalanceResult.class);
   }
 
+  @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);
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java
index ba1129718..d5ee9dfeb 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PartnerTransferServiceImpl.java
+++ b/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);
   }
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java
index 10b1d8020..97e85f413 100644
--- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java
+++ b/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;
@@ -125,6 +126,12 @@ public class EcommerceServiceImplTest {
     wxPayService.getEcommerceService().subNowBalance(subMchid);
   }
 
+  @Test
+  public void testSubNowBalanceWithAccountType() throws WxPayException {
+    String subMchid = "";
+    wxPayService.getEcommerceService().subNowBalance(subMchid, SpAccountTypeEnum.BASIC);
+  }
+
   @Test
   public void testAddReceivers() throws WxPayException {
     ProfitSharingReceiverRequest request = new ProfitSharingReceiverRequest();