소스 검색

:bug: #1959 【微信支付】电商收付通修复请求分账接口异常问题

Co-authored-by: aha <aha>
guicw 4 년 전
부모
커밋
04fadf6f71

+ 5 - 1
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java

@@ -1,10 +1,12 @@
 package com.github.binarywang.wxpay.bean.ecommerce;
 
+import com.github.binarywang.wxpay.v3.SpecEncrypt;
 import com.google.gson.annotations.SerializedName;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
+import java.util.List;
 
 /**
  * 请求分账 对象
@@ -86,7 +88,8 @@ public class ProfitSharingRequest implements Serializable {
    * </pre>
    */
   @SerializedName(value = "receivers")
-  private Receiver[] receivers;
+  @SpecEncrypt
+  private List<Receiver> receivers;
 
   /**
    * <pre>
@@ -186,6 +189,7 @@ public class ProfitSharingRequest implements Serializable {
      * </pre>
      */
     @SerializedName(value = "receiver_name")
+    @SpecEncrypt
     private String receiverName;
 
   }

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

@@ -190,7 +190,8 @@ public class EcommerceServiceImpl implements EcommerceService {
   @Override
   public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException {
     String url = String.format("%s/v3/ecommerce/profitsharing/orders", this.payService.getPayBaseUrl());
-    String response = this.payService.postV3(url, GSON.toJson(request));
+    RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate());
+    String response = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
     return GSON.fromJson(response, ProfitSharingResult.class);
   }
 

+ 13 - 2
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/util/RsaCryptoUtil.java

@@ -15,6 +15,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.PrivateKey;
 import java.security.cert.X509Certificate;
 import java.util.Base64;
+import java.util.Collection;
 
 /**
  * 微信支付敏感信息加密
@@ -53,8 +54,18 @@ public class RsaCryptoUtil {
         } else {
           field.setAccessible(true);
           Object obj = field.get(encryptObject);
-          if (obj != null) {
-            encryptField(field.get(encryptObject), certificate);
+          if (obj == null) {
+            continue;
+          }
+          if (obj instanceof Collection) {
+            Collection collection = (Collection) obj;
+            for (Object o : collection) {
+              if (o != null) {
+                encryptField(o, certificate);
+              }
+            }
+          } else {
+            encryptField(obj, certificate);
           }
         }
       }