diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverRequest.java new file mode 100644 index 000000000..a5cc6e17d --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverRequest.java @@ -0,0 +1,120 @@ +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; + +/** + * 添加分账接收方API + *
+ * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml
+ * 
+ */ +@Data +@NoArgsConstructor +public class ProfitSharingReceiverRequest implements Serializable { + + /** + *
+   * 字段名:公众账号ID
+   * 变量名:appid
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  电商平台的appid(公众号APPID或者小程序APPID)
+   * 示例值:wx8888888888888888
+   * 
+ */ + @SerializedName(value = "appid") + private String appid; + + /** + *
+   * 字段名:接收方类型
+   * 变量名:type
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账接收方的类型,枚举值:
+   *    MERCHANT_ID:商户
+   *    PERSONAL_OPENID:个人
+   * 示例值:MERCHANT_ID
+   * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+   * 字段名:接收方账号
+   * 变量名:account
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  分账接收方的账号
+   *    类型是MERCHANT_ID时,是商户号
+   *    类型是PERSONAL_OPENID时,是个人openid,openid获取方法
+   * 示例值:190001001
+   * 
+ */ + @SerializedName(value = "account") + private String account; + + /** + *
+   * 字段名:接收方名称
+   * 变量名:name
+   * 是否必填:是
+   * 类型:string(256)
+   * 描述:
+   *  分账接收方的名称,当type为MERCHANT_ID时,接收方名称是商户全称。
+   * 示例值:张三网络公司
+   * 
+ */ + @SerializedName(value = "name") + private String name; + + /** + *
+   * 字段名:接收方名称的密文
+   * 变量名:encrypted_name
+   * 是否必填:否
+   * 类型:string(10240)
+   * 描述:
+   *  1、分账接收方类型是PERSONAL_OPENID时,是个人姓名的密文(选传,传则校验)
+   * 此字段的加密的方式为:
+   *    2、使用微信支付平台证书中的公钥
+   *    3、使用RSAES-OAEP算法进行加密
+   *    4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号
+   *  字段加密: 使用APIv3定义的方式加密
+   * 示例值:hu89ohu89ohu89o
+   * 
+ */ + @SpecEncrypt + @SerializedName(value = "encrypted_name") + private String encryptedName; + + /** + *
+   * 字段名:与分账方的关系类型
+   * 变量名:relation_type
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  子商户与接收方的关系。
+   * 枚举值:
+   *    SUPPLIER:供应商
+   *    DISTRIBUTOR:分销商
+   *    SERVICE_PROVIDER:服务商
+   *    PLATFORM:平台
+   *    OTHERS:其他
+   * 示例值:SUPPLIER
+   * 
+ */ + @SerializedName(value = "relation_type") + private String relationType; + +} diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverResult.java new file mode 100644 index 000000000..b4e477e92 --- /dev/null +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingReceiverResult.java @@ -0,0 +1,44 @@ +package com.github.binarywang.wxpay.bean.ecommerce; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +public class ProfitSharingReceiverResult implements Serializable { + + /** + *
+   * 字段名:接收方类型
+   * 变量名:type
+   * 是否必填:是
+   * 类型:string(32)
+   * 描述:
+   *  分账接收方的类型,枚举值:
+   *    MERCHANT_ID:商户
+   *    PERSONAL_OPENID:个人
+   * 示例值:MERCHANT_ID
+   * 
+ */ + @SerializedName(value = "type") + private String type; + + /** + *
+   * 字段名:接收方账号
+   * 变量名:account
+   * 是否必填:是
+   * 类型:string(64)
+   * 描述:
+   *  分账接收方的账号
+   *    类型是MERCHANT_ID时,是商户号
+   *    类型是PERSONAL_OPENID时,是个人openid,openid获取方法
+   * 示例值:190001001
+   * 
+ */ + @SerializedName(value = "account") + private String account; +} 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 cdca94462..9df71e20d 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 @@ -251,6 +251,30 @@ public interface EcommerceService { */ ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException; + /** + *
+   * 添加分账接收方API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml
+   * 
+ * + * @param request 添加分账接收方 + * @return 返回数据 profit sharing result + * @throws WxPayException the wx pay exception + */ + ProfitSharingReceiverResult addReceivers(ProfitSharingReceiverRequest request) throws WxPayException; + + /** + *
+   * 删除分账接收方API
+   * 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_8.shtml
+   * 
+ * + * @param request 删除分账接收方 + * @return 返回数据 profit sharing result + * @throws WxPayException the wx pay exception + */ + ProfitSharingReceiverResult deleteReceivers(ProfitSharingReceiverRequest request) throws WxPayException; + /** *
    * 请求分账回退API
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 169f59371..5366fb08d 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
@@ -203,6 +203,20 @@ public class EcommerceServiceImpl implements EcommerceService {
     return GSON.fromJson(response, ProfitSharingResult.class);
   }
 
+  @Override
+  public ProfitSharingReceiverResult addReceivers(ProfitSharingReceiverRequest request) throws WxPayException {
+    String url = String.format("%s/v3/ecommerce/profitsharing/receivers/add", this.payService.getPayBaseUrl());
+    String response = this.payService.postV3(url, GSON.toJson(request));
+    return GSON.fromJson(response, ProfitSharingReceiverResult.class);
+  }
+
+  @Override
+  public ProfitSharingReceiverResult deleteReceivers(ProfitSharingReceiverRequest request) throws WxPayException {
+    String url = String.format("%s/v3/ecommerce/profitsharing/receivers/delete", this.payService.getPayBaseUrl());
+    String response = this.payService.postV3(url, GSON.toJson(request));
+    return GSON.fromJson(response, ProfitSharingReceiverResult.class);
+  }
+
   @Override
   public ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException {
     String url = String.format("%s/v3/ecommerce/profitsharing/returnorders", this.payService.getPayBaseUrl());
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 b56084466..10b1d8020 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
@@ -1,17 +1,25 @@
 package com.github.binarywang.wxpay.service.impl;
 
+import com.github.binarywang.wxpay.bean.ecommerce.CombineTransactionsRequest;
 import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsQueryRequest;
 import com.github.binarywang.wxpay.bean.ecommerce.PartnerTransactionsResult;
+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.TradeTypeEnum;
 import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.testbase.ApiTestModule;
+import com.google.gson.GsonBuilder;
 import com.google.inject.Inject;
 import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.util.RandomUtils;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
 
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
 
 @Slf4j
 @Test
@@ -19,10 +27,10 @@ import java.nio.charset.StandardCharsets;
 public class EcommerceServiceImplTest {
 
   @Inject
-  private  WxPayService wxPayService;
+  private WxPayService wxPayService;
 
   @Test
-  public void testNotifySign(){
+  public void testNotifySign() {
     //通知报文主体
     String notifyData = "";
     //请求头  Wechatpay-Timestamp
@@ -49,6 +57,53 @@ public class EcommerceServiceImplTest {
     log.info("签名结果:{} \nheader:{} \ndata:{}", signResult, header, notifyData);
   }
 
+  @Test
+  public void testCombinePay() throws WxPayException {
+    String outTradeNo = RandomUtils.getRandomStr();
+    String notifyUrl = "https://api.qq.com/";
+    System.out.println("outTradeNo = " + outTradeNo);
+    CombineTransactionsRequest request = new CombineTransactionsRequest();
+    request.setCombineAppid("");
+    request.setCombineMchid("");
+    request.setCombineOutTradeNo(outTradeNo);
+    request.setNotifyUrl(notifyUrl);
+
+    CombineTransactionsRequest.CombinePayerInfo payerInfo = new CombineTransactionsRequest.CombinePayerInfo();
+    payerInfo.setOpenid("");
+    request.setCombinePayerInfo(payerInfo);
+
+    //构建金额信息
+    CombineTransactionsRequest.Amount requestAmount = new CombineTransactionsRequest.Amount();
+    //设置币种信息
+    requestAmount.setCurrency("CNY");
+    //设置金额
+    requestAmount.setTotalAmount(1);
+
+    CombineTransactionsRequest.SubOrders subOrder1 = new CombineTransactionsRequest.SubOrders();
+    //设置 子单商户号  mchId 和 combine_mchId 取值一样
+    subOrder1.setMchid("");
+    String subOrderNo1 = outTradeNo + "1";
+    subOrder1.setAttach(subOrderNo1);
+    subOrder1.setOutTradeNo(subOrderNo1);
+    subOrder1.setDescription("订单1");
+    subOrder1.setAmount(requestAmount);
+
+    CombineTransactionsRequest.SubOrders subOrder2 = new CombineTransactionsRequest.SubOrders();
+    //设置 子单商户号  mchId 和 combine_mchId 取值一样
+    subOrder2.setMchid("");
+    String subOrderNo2 = outTradeNo + "2";
+    subOrder2.setAttach(subOrderNo2);
+    subOrder2.setOutTradeNo(subOrderNo2);
+    subOrder2.setSubMchid("");
+    subOrder2.setDescription("订单2");
+    subOrder2.setAmount(requestAmount);
+
+    request.setSubOrders(Arrays.asList(subOrder1, subOrder2));
+    TransactionsResult result = wxPayService.getEcommerceService().combine(TradeTypeEnum.JSAPI, request);
+
+    System.out.println("result = " + result);
+  }
+
   @Test
   public void testQueryPartnerTransactions() throws WxPayException {
     PartnerTransactionsQueryRequest request = new PartnerTransactionsQueryRequest();
@@ -60,7 +115,8 @@ public class EcommerceServiceImplTest {
     request.setOutTradeNo("");
     //微信订单号
     request.setTransactionId("");
-    wxPayService.getEcommerceService().queryPartnerTransactions(request);
+    PartnerTransactionsResult result = wxPayService.getEcommerceService().queryPartnerTransactions(request);
+    System.out.println("result = " + result);
   }
 
   @Test
@@ -69,10 +125,23 @@ public class EcommerceServiceImplTest {
     wxPayService.getEcommerceService().subNowBalance(subMchid);
   }
 
+  @Test
+  public void testAddReceivers() throws WxPayException {
+    ProfitSharingReceiverRequest request = new ProfitSharingReceiverRequest();
+    request.setAppid("wx8888888888888888");
+    request.setType("MERCHANT_ID");
+    request.setAccount("190001001");
+    request.setName("张三网络公司");
+    request.setRelationType("SUPPLIER");
+
+    ProfitSharingReceiverResult result = wxPayService.getEcommerceService().addReceivers(request);
+    System.out.println("result = " + result);
+  }
+
   @Test
   public void testSubDayEndBalance() throws WxPayException {
     String subMchid = "";
     String date = "";
-    wxPayService.getEcommerceService().subDayEndBalance(subMchid,date);
+    wxPayService.getEcommerceService().subDayEndBalance(subMchid, date);
   }
 }