🆕 #1923 【微信支付】电商收付通增加添加、删除分账接收方等接口
This commit is contained in:
@@ -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
|
||||
* <pre>
|
||||
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml
|
||||
* </pre>
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ProfitSharingReceiverRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:公众账号ID
|
||||
* 变量名:appid
|
||||
* 是否必填:是
|
||||
* 类型:string(32)
|
||||
* 描述:
|
||||
* 电商平台的appid(公众号APPID或者小程序APPID)
|
||||
* 示例值:wx8888888888888888
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "appid")
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方类型
|
||||
* 变量名:type
|
||||
* 是否必填:是
|
||||
* 类型:string(32)
|
||||
* 描述:
|
||||
* 分账接收方的类型,枚举值:
|
||||
* MERCHANT_ID:商户
|
||||
* PERSONAL_OPENID:个人
|
||||
* 示例值:MERCHANT_ID
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方账号
|
||||
* 变量名:account
|
||||
* 是否必填:是
|
||||
* 类型:string(64)
|
||||
* 描述:
|
||||
* 分账接收方的账号
|
||||
* 类型是MERCHANT_ID时,是商户号
|
||||
* 类型是PERSONAL_OPENID时,是个人openid,openid获取方法
|
||||
* 示例值:190001001
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "account")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方名称
|
||||
* 变量名:name
|
||||
* 是否必填:是
|
||||
* 类型:string(256)
|
||||
* 描述:
|
||||
* 分账接收方的名称,当type为MERCHANT_ID时,接收方名称是商户全称。
|
||||
* 示例值:张三网络公司
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方名称的密文
|
||||
* 变量名:encrypted_name
|
||||
* 是否必填:否
|
||||
* 类型:string(10240)
|
||||
* 描述:
|
||||
* 1、分账接收方类型是PERSONAL_OPENID时,是个人姓名的密文(选传,传则校验)
|
||||
* 此字段的加密的方式为:
|
||||
* 2、使用微信支付平台证书中的公钥
|
||||
* 3、使用RSAES-OAEP算法进行加密
|
||||
* 4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号
|
||||
* 字段加密: 使用APIv3定义的方式加密
|
||||
* 示例值:hu89ohu89ohu89o
|
||||
* </pre>
|
||||
*/
|
||||
@SpecEncrypt
|
||||
@SerializedName(value = "encrypted_name")
|
||||
private String encryptedName;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:与分账方的关系类型
|
||||
* 变量名:relation_type
|
||||
* 是否必填:是
|
||||
* 类型:string(32)
|
||||
* 描述:
|
||||
* 子商户与接收方的关系。
|
||||
* 枚举值:
|
||||
* SUPPLIER:供应商
|
||||
* DISTRIBUTOR:分销商
|
||||
* SERVICE_PROVIDER:服务商
|
||||
* PLATFORM:平台
|
||||
* OTHERS:其他
|
||||
* 示例值:SUPPLIER
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "relation_type")
|
||||
private String relationType;
|
||||
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方类型
|
||||
* 变量名:type
|
||||
* 是否必填:是
|
||||
* 类型:string(32)
|
||||
* 描述:
|
||||
* 分账接收方的类型,枚举值:
|
||||
* MERCHANT_ID:商户
|
||||
* PERSONAL_OPENID:个人
|
||||
* 示例值:MERCHANT_ID
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "type")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 字段名:接收方账号
|
||||
* 变量名:account
|
||||
* 是否必填:是
|
||||
* 类型:string(64)
|
||||
* 描述:
|
||||
* 分账接收方的账号
|
||||
* 类型是MERCHANT_ID时,是商户号
|
||||
* 类型是PERSONAL_OPENID时,是个人openid,openid获取方法
|
||||
* 示例值:190001001
|
||||
* </pre>
|
||||
*/
|
||||
@SerializedName(value = "account")
|
||||
private String account;
|
||||
}
|
||||
@@ -251,6 +251,30 @@ public interface EcommerceService {
|
||||
*/
|
||||
ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 添加分账接收方API
|
||||
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_7.shtml
|
||||
* </pre>
|
||||
*
|
||||
* @param request 添加分账接收方
|
||||
* @return 返回数据 profit sharing result
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
ProfitSharingReceiverResult addReceivers(ProfitSharingReceiverRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 删除分账接收方API
|
||||
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_8.shtml
|
||||
* </pre>
|
||||
*
|
||||
* @param request 删除分账接收方
|
||||
* @return 返回数据 profit sharing result
|
||||
* @throws WxPayException the wx pay exception
|
||||
*/
|
||||
ProfitSharingReceiverResult deleteReceivers(ProfitSharingReceiverRequest request) throws WxPayException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 请求分账回退API
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user