微信支付分帐相关API

This commit is contained in:
Kit 2020-05-26 10:54:30 +08:00
parent 91d880eb7f
commit 431ef21964
24 changed files with 1454 additions and 34 deletions

View File

@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<name>weixin4j-pay</name>
<artifactId>weixin4j-pay</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0</version>
<url>https://github.com/foxinmy/weixin4j/tree/master/weixin4j-pay</url>
<description>微信支付商户平台API</description>
<developers>

View File

@ -10,10 +10,12 @@ import com.foxinmy.weixin4j.pay.payment.coupon.*;
import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfo;
import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfoRequest;
import com.foxinmy.weixin4j.pay.payment.mch.*;
import com.foxinmy.weixin4j.pay.profitsharing.*;
import com.foxinmy.weixin4j.pay.sign.WeixinSignature;
import com.foxinmy.weixin4j.pay.type.*;
import com.foxinmy.weixin4j.pay.type.mch.BillType;
import com.foxinmy.weixin4j.pay.type.mch.RefundAccountType;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
import com.foxinmy.weixin4j.util.Consts;
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
@ -53,6 +55,10 @@ public class WeixinPayProxy {
* 商户信息
*/
private final WeixinPayAccount weixinPayAccount;
/**
* 分帐接口
*/
private final ProfitSharingApi profitSharingApi;
/**
* 微信支付接口实现(使用weixin4j.properties配置的account商户信息)
@ -78,6 +84,7 @@ public class WeixinPayProxy {
this.couponApi = new CouponApi(weixinPayAccount);
this.cashApi = new CashApi(weixinPayAccount);
this.customsApi = new CustomsApi(weixinPayAccount);
this.profitSharingApi = new ProfitSharingApi(weixinPayAccount);
}
/**
@ -886,5 +893,141 @@ public class WeixinPayProxy {
return payApi.getWxPayfaceAuthinfo(request);
}
/**
* 添加分账接收方
* 服务商代子商户发起添加分账接收方请求后续可通过发起分账请求将结算后的钱分到该分账接收方
*
* @param receiver
* 分帐接收方
* @return
* @throws WeixinException
* @see Receiver
* @see ReceiverResult
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_3&index=4">添加分账接收方</a>
* @since weixin4j-pay 1.1.0
*
*/
public ReceiverResult addProfitSharingReceiver(Receiver receiver) throws WeixinException {
return profitSharingApi.addReceiver(receiver);
}
/**
* 删除分账接收方
* 商户发起删除分账接收方请求删除后不支持将结算后的钱分到该分账接收方
*
* @param receiver
* 分帐接收方
* @return
* @throws WeixinException
* @see Receiver
* @see ReceiverResult
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_4&index=5">删除分账接收方</a>
* @since weixin4j-pay 1.1.0
*/
public ReceiverResult removeProfitSharingReceiver(Receiver receiver) throws WeixinException {
return profitSharingApi.removeReceiver(receiver);
}
/**
* 请求分帐
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @param receivers
* 分帐接收方列表
* @param multi
* 是否多次分帐默认为单次分帐即调用分帐成功后马上解冻剩余金额给商户不需要完结分帐多次分帐可多次调用分帐API需调完结分帐结束分帐
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_1&index=1">请求单次分帐</a>
* @since weixin4j-pay 1.1.0
*/
public ProfitSharingResult profitSharing(String transactionId, String outOrderNo, List<ReceiverProfit> receivers,
Boolean multi) throws WeixinException{
return profitSharingApi.profitSharing(transactionId, outOrderNo, receivers, multi);
}
/**
* 分帐查询
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_2&index=3">分帐查询</a>
* @since weixin4j-pay 1.1.0
*/
public ProfitSharingResult profitSharingQuery(String transactionId, String outOrderNo) throws WeixinException{
return profitSharingApi.profitSharingQuery(transactionId, outOrderNo);
}
/**
* 完结分账
* 1不需要进行分账的订单可直接调用本接口将订单的金额全部解冻给本商户
* 2调用多次分账接口后需要解冻剩余资金时调用本接口将剩余的分账金额全部解冻给特约商户
* 3已调用请求单次分账后剩余待分账金额为零不需要再调用此接口
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @param description
* 分帐完结描述
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_5&index=6">完结分账</a>
* @since weixin4j-pay 1.1.0
*/
public ProfitSharingResult profitSharingFinish(String transactionId, String outOrderNo, String description)
throws WeixinException{
return profitSharingApi.profitSharingFinish(transactionId, outOrderNo, description);
}
/**
* 分账回退
*
* @param id
* 分帐单号
* @param outReturnNo
* 商户回退单号
* @param returnAccountType
* 回退方类型
* @param returnAccount
* 回退方账号
* @param description
* 回退描述
* @return
* @throws WeixinException
* @see ProfitSharingReturnRequest
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_7&index=7">分账回退</a>
* @since weixin4j-pay 1.1.0
*/
public ProfitSharingReturnResult profitSharingReturn(ProfitId id, String outReturnNo,
ReturnAccountType returnAccountType, String returnAccount,
String description)
throws WeixinException{
return profitSharingApi.profitSharingReturn(id, outReturnNo, returnAccountType, returnAccount, description);
}
/**
* 回退结果查询
*
* @param id
* 分帐单号
* @param outReturnNo
* 商户回退单号
* @return
* @throws WeixinException
* @see ProfitSharingReturnRequest
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_8&index=8">回退结果查询</a>
*/
public ProfitSharingReturnResult profitSharingReturnQuery(ProfitId id, String outReturnNo) throws WeixinException{
return profitSharingApi.profitSharingReturnQuery(id, outReturnNo);
}
public final static String VERSION = Consts.VERSION;
}

View File

@ -10,7 +10,6 @@ import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfo;
import com.foxinmy.weixin4j.pay.payment.face.PayfaceAuthinfoRequest;
import com.foxinmy.weixin4j.pay.payment.mch.*;
import com.foxinmy.weixin4j.pay.type.mch.BillType;
import com.foxinmy.weixin4j.pay.type.mch.DepositType;
import com.foxinmy.weixin4j.pay.type.mch.RefundAccountType;
import com.foxinmy.weixin4j.pay.type.*;
import com.foxinmy.weixin4j.util.*;
@ -89,13 +88,13 @@ public class PayApi extends MchApi {
payPackage.getAuthCode(), null, payPackage.getAttach(),
null, null, payPackage.getGoodsTag(),
payPackage.getLimitPay(), payPackage.getSubAppId(), payPackage.getFaceCode(),
payPackage.getDeposit());
payPackage.getDeposit(), payPackage.getProfitSharing());
// 默认为MD5签名
SignType signType= SignType.MD5;
super.declareMerchant(_payPackage);
// 默认为刷卡支付付款码支付的API地址
String url = getRequestUri("micropay_uri");
if(payPackage.getDeposit()==DepositType.Y){
if(payPackage.getDeposit()==YesNoType.Y){
// 押金支付只支持HMAC-SHA256签名
signType = SignType.HMAC$SHA256;
_payPackage.setSignType("HMAC-SHA256");
@ -791,6 +790,23 @@ public class PayApi extends MchApi {
return createPayRequest(payPackage);
}
/**
* 创建押金支付
*
* @param code
* @param body
* @param outTradeNo
* @param totalFee
* @param createIp
* @param openId
* @param attach
* @param store
* @param isFacePay
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_1&index=2">支付押金付款码支付</a>
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/deposit_sl.php?chapter=27_0&index=1">支付押金人脸支付</a>
*/
public MchPayRequest createDepositPayRequest(String code, String body, String outTradeNo, double totalFee,
String createIp, String openId, String attach, SceneInfoStore store,
boolean isFacePay) throws WeixinException {
@ -799,12 +815,12 @@ public class PayApi extends MchApi {
payPackage = new MchPayPackage(body, outTradeNo, totalFee, null, createIp, TradeType.FACEPAY,
openId, null, null, attach);
payPackage.setFaceCode(code);
payPackage.setDeposit(DepositType.Y);
payPackage.setDeposit(YesNoType.Y);
return createPayRequest(payPackage);
}else{
payPackage = new MchPayPackage(body, outTradeNo, totalFee, null, createIp, TradeType.MICROPAY,
openId, code, null, attach);
payPackage.setDeposit(DepositType.Y);
payPackage.setDeposit(YesNoType.Y);
if (store != null) {
payPackage.setSceneInfo(String.format("{\"store_info\":\"%s\"}",
JSON.toJSONString(store)));

View File

@ -0,0 +1,211 @@
package com.foxinmy.weixin4j.pay.api;
import com.alibaba.fastjson.TypeReference;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
import com.foxinmy.weixin4j.pay.profitsharing.*;
import com.foxinmy.weixin4j.pay.type.ProfitIdType;
import com.foxinmy.weixin4j.pay.type.SignType;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
import com.foxinmy.weixin4j.xml.XmlStream;
import java.util.List;
/**
* 微信商户平台分账接口直连商户/服务商
*
* @author kit (kit.li@qq.com)
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public class ProfitSharingApi extends MchApi {
public ProfitSharingApi(WeixinPayAccount weixinAccount) {
super(weixinAccount);
}
/**
* 添加分账接收方
* 服务商代子商户发起添加分账接收方请求后续可通过发起分账请求将结算后的钱分到该分账接收方
*
* @param receiver
* 分帐接收方
* @return
* @see Receiver
* @see ReceiverResult
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=25_3&index=4">添加分账接收方</a>
*
*/
public ReceiverResult addReceiver(Receiver receiver) throws WeixinException {
ReceiverRequest receiverRequest = new ReceiverRequest(receiver);
super.declareMerchant(receiverRequest);
String url = getRequestUri("profit_sharing_add_receiver_uri");
receiverRequest.setSign(weixinSignature.sign(receiverRequest, SignType.HMAC$SHA256));
String para = XmlStream.toXML(receiverRequest);
WeixinResponse response = weixinExecutor.post(url, para);
return response.getAsObject(new TypeReference<ReceiverResult>(){});
}
/**
* 删除分账接收方
* 商户发起删除分账接收方请求删除后不支持将结算后的钱分到该分账接收方
*
* @param receiver
* 分帐接收方
* @return
* @throws WeixinException
* @see Receiver
* @see ReceiverResult
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_4&index=5">删除分账接收方</a>
*/
public ReceiverResult removeReceiver(Receiver receiver) throws WeixinException {
ReceiverRequest receiverRequest = new ReceiverRequest(receiver);
super.declareMerchant(receiverRequest);
String url = getRequestUri("profit_sharing_remove_receiver_uri");
receiverRequest.setSign(weixinSignature.sign(receiverRequest, SignType.HMAC$SHA256));
String para = XmlStream.toXML(receiverRequest);
WeixinResponse response = weixinExecutor.post(url, para);
return response.getAsObject(new TypeReference<ReceiverResult>(){});
}
/**
* 请求分帐
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @param receivers
* 分帐接收方
* @param multi
* 是否多次分帐默认为单次分帐即调用分帐成功后马上解冻剩余金额给商户不需要完结分帐多次分帐可多次调用分帐API需调完结分帐结束分帐
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_1&index=1">请求单次分帐</a>
*/
public ProfitSharingResult profitSharing(String transactionId, String outOrderNo, List<ReceiverProfit> receivers,
Boolean multi) throws WeixinException {
ProfitSharingRequest request = new ProfitSharingRequest(transactionId, outOrderNo, receivers);
super.declareMerchant(request);
String url = multi==null || multi.booleanValue()==false ? getRequestUri("profit_sharing_uri") :
getRequestUri("multi_profit_sharing_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);
WeixinResponse response = getWeixinSSLExecutor().post(url, para);
return response.getAsObject(new TypeReference<ProfitSharingResult>(){});
}
/**
* 分帐查询
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_2&index=3">分帐查询</a>
*/
public ProfitSharingResult profitSharingQuery(String transactionId, String outOrderNo) throws WeixinException {
ProfitSharingRequest request = new ProfitSharingRequest(transactionId, outOrderNo, null);
super.declareMerchant(request);
String url = getRequestUri("profit_sharing_query_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);
WeixinResponse response = weixinExecutor.post(url, para);
return response.getAsObject(new TypeReference<ProfitSharingResult>(){});
}
/**
* 完结分账
* 1不需要进行分账的订单可直接调用本接口将订单的金额全部解冻给本商户
* 2调用多次分账接口后需要解冻剩余资金时调用本接口将剩余的分账金额全部解冻给特约商户
* 3已调用请求单次分账后剩余待分账金额为零不需要再调用此接口
*
* @param transactionId
* 微信订单号
* @param outOrderNo
* 商户分帐单号
* @param description
* 分帐完结描述
* @return
* @throws WeixinException
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_5&index=6">完结分账</a>
*/
public ProfitSharingResult profitSharingFinish(String transactionId, String outOrderNo, String description)
throws WeixinException {
ProfitSharingRequest request = new ProfitSharingRequest(transactionId, outOrderNo, null);
request.setDescription(description);
super.declareMerchant(request);
String url = getRequestUri("profit_sharing_finish_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);
WeixinResponse response = getWeixinSSLExecutor().post(url, para);
return response.getAsObject(new TypeReference<ProfitSharingResult>(){});
}
/**
* 分账回退
*
* @param id
* 分帐单号
* @param outReturnNo
* 商户回退单号
* @param returnAccountType
* 回退方类型
* @param returnAccount
* 回退方账号
* @param description
* 回退描述
* @return
* @throws WeixinException
* @see ProfitSharingReturnRequest
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_7&index=7">分账回退</a>
*/
public ProfitSharingReturnResult profitSharingReturn(ProfitId id, String outReturnNo,
ReturnAccountType returnAccountType, String returnAccount,
String description) throws WeixinException{
ProfitSharingReturnRequest request;
if(id.getIdType()== ProfitIdType.ORDER_ID){
request = new ProfitSharingReturnRequest(id.getId(), null, outReturnNo, returnAccountType,
returnAccount, description);
}else{
request = new ProfitSharingReturnRequest(null, id.getId(), outReturnNo, returnAccountType,
returnAccount, description);
}
super.declareMerchant(request);
String url = getRequestUri("profit_sharing_return_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);
WeixinResponse response = getWeixinSSLExecutor().post(url, para);
return response.getAsObject(new TypeReference<ProfitSharingReturnResult>(){});
}
/**
* 回退结果查询
*
* @param id
* 分帐单号
* @param outReturnNo
* 商户回退单号
* @return
* @throws WeixinException
* @see ProfitSharingReturnRequest
* @see <a href="https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=27_8&index=8">回退结果查询</a>
*/
public ProfitSharingReturnResult profitSharingReturnQuery(ProfitId id, String outReturnNo) throws WeixinException{
ProfitSharingReturnRequest request;
if(id.getIdType()== ProfitIdType.ORDER_ID){
request = new ProfitSharingReturnRequest(id.getId(), null, outReturnNo);
}else{
request = new ProfitSharingReturnRequest(null, id.getId(), outReturnNo);
}
super.declareMerchant(request);
String url = getRequestUri("profit_sharing_return_query_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);
WeixinResponse response = weixinExecutor.post(url, para);
return response.getAsObject(new TypeReference<ProfitSharingReturnResult>(){});
}
}

View File

@ -4,7 +4,7 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.PayPackage;
import com.foxinmy.weixin4j.pay.type.CurrencyType;
import com.foxinmy.weixin4j.pay.type.TradeType;
import com.foxinmy.weixin4j.pay.type.mch.DepositType;
import com.foxinmy.weixin4j.pay.type.YesNoType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -88,7 +88,13 @@ public class MchPayPackage extends PayPackage {
*/
@XmlElement(name = "deposit")
@JSONField(name = "deposit")
private DepositType deposit;
private YesNoType deposit;
/**
* 是否需要分帐非必传默认为不分帐
* Y-需要分账N-不分账
*/
private YesNoType profitSharing;
protected MchPayPackage() {
// jaxb required
@ -123,7 +129,7 @@ public class MchPayPackage extends PayPackage {
String openId, String authCode, String productId, String attach) {
this(body, null, outTradeNo, totalFee, CurrencyType.CNY, notifyUrl,
createIp, tradeType, openId, authCode, productId, attach, null,
null, null, null, null, null, null);
null, null, null, null, null, null, null);
}
/**
@ -168,13 +174,15 @@ public class MchPayPackage extends PayPackage {
* 人脸凭证用于旧版刷脸支付
* @param depositType
* 是否押金支付
* @param profitSharing
* 是否需要分账
*/
public MchPayPackage(String body, String detial, String outTradeNo,
double totalFee, CurrencyType feeType, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String authCode, String productId, String attach, Date timeStart,
Date timeExpire, String goodsTag, String limitPay, String subOpenId, String faceCode,
DepositType depositType) {
YesNoType depositType, YesNoType profitSharing) {
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
timeStart, timeExpire, goodsTag);
this.tradeType = tradeType != null ? tradeType.name() : null;
@ -261,14 +269,22 @@ public class MchPayPackage extends PayPackage {
this.faceCode = faceCode;
}
public DepositType getDeposit() {
public YesNoType getDeposit() {
return deposit;
}
public void setDeposit(DepositType deposit) {
public void setDeposit(YesNoType deposit) {
this.deposit = deposit;
}
public YesNoType getProfitSharing() {
return profitSharing;
}
public void setProfitSharing(YesNoType profitSharing) {
this.profitSharing = profitSharing;
}
@Override
public String toString() {
return "MchPayPackage{" +
@ -282,6 +298,7 @@ public class MchPayPackage extends PayPackage {
", sceneInfo='" + sceneInfo + '\'' +
", faceCode='" + faceCode + '\'' +
", deposit=" + deposit +
", profitSharing=" + profitSharing +
'}';
}
}

View File

@ -0,0 +1,36 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.foxinmy.weixin4j.pay.type.ProfitIdType;
/**
* 分帐单单号
*
* @author kit
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public class ProfitId {
private String id;
private ProfitIdType idType;
public ProfitId(String id, ProfitIdType type){
this.id = id;
this.idType = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public ProfitIdType getIdType() {
return idType;
}
public void setIdType(ProfitIdType idType) {
this.idType = idType;
}
}

View File

@ -0,0 +1,86 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
/**
* 单次分帐的请求内容
*
* @author kit(kit.li@qq.com)
* @date 2020年5月25日
* @since weixin4j-pay 1.1.0
*/
public class ProfitSharingRequest extends MerchantResult {
/**
* 只支持HMAC-SHA256
*/
@XmlElement(name = "sign_type")
@JSONField(name = "sign_type")
private final String signType = "HMAC-SHA256";
/**
* 微信支付订单号
*/
@XmlElement(name = "transaction_id")
@JSONField(name = "transaction_id")
private String transactionId;
/**
* 商户订单号
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
private String outOrderNo;
/**
* 分账接收方列表不超过50个
*/
private List<ReceiverProfit> receivers;
/**
* 分账完结描述
*/
private String description;
public ProfitSharingRequest(String transactionId, String outOrderNo, List<ReceiverProfit> receivers){
this.transactionId = transactionId;
this.outOrderNo = outOrderNo;
this.receivers = receivers;
}
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getOutOrderNo() {
return outOrderNo;
}
public void setOutOrderNo(String outOrderNo) {
this.outOrderNo = outOrderNo;
}
public List<ReceiverProfit> getReceivers() {
return receivers;
}
public void setReceivers(List<ReceiverProfit> receivers) {
this.receivers = receivers;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String getSignType() {
return signType;
}
}

View File

@ -0,0 +1,127 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
/**
* 单次分帐返回结果
*
* @author kit
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public class ProfitSharingResult extends MerchantResult {
/**
* 微信支付订单号
*/
@XmlElement(name = "transaction_id")
@JSONField(name = "transaction_id")
private String transactionId;
/**
* 商户订单号
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
private String outOrderNo;
/**
* 微信分帐单号
*/
@XmlElement(name = "order_id")
@JSONField(name = "order_id")
private String orderId;
/**
* 分账单状态分帐查询
* ACCEPTED受理成功
* PROCESSING处理中
* FINISHED处理完成
* CLOSED处理失败已关单
*/
private String status;
/**
* 关单原因分帐查询非必传默认值NO_AUTH----分账授权已解除
*/
@XmlElement(name = "close_reason")
@JSONField(name = "close_reason")
private String closeReason;
/**
* 分账接收方列表分帐查询
*/
private List<ReceiverProfitResult> receivers;
/**
* 分账金额分帐查询
* 分账完结的分账金额单位为分 仅当查询分账完结的执行结果时存在本字段
*/
private Integer amount;
/**
* 分帐描述分帐查询
* 分账完结的原因描述仅当查询分账完结的执行结果时存在本字段
*/
private String description;
public String getTransactionId() {
return transactionId;
}
public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}
public String getOutOrderNo() {
return outOrderNo;
}
public void setOutOrderNo(String outOrderNo) {
this.outOrderNo = outOrderNo;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCloseReason() {
return closeReason;
}
public void setCloseReason(String closeReason) {
this.closeReason = closeReason;
}
public List<ReceiverProfitResult> getReceivers() {
return receivers;
}
public void setReceivers(List<ReceiverProfitResult> receivers) {
this.receivers = receivers;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,153 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
import javax.xml.bind.annotation.XmlElement;
/**
* 分帐回退API请求内容
*
* @author kit (kit.li@qq.com)
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public class ProfitSharingReturnRequest extends MerchantResult {
/**
* 只支持HMAC-SHA256
*/
@XmlElement(name = "sign_type")
@JSONField(name = "sign_type")
private final String signType = "HMAC-SHA256";
/**
* 微信分帐单号
* 原发起分账请求时微信返回的微信分账单号与商户分账单号一一对应微信分账单号与商户分账单号二选一填写
*/
private String orderId;
/**
* 商户订单号
* 原发起分账请求时使用的商户系统内部的分账单号微信分账单号与商户分账单号二选一填写
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
private String outOrderNo;
/**
* 商户回退单号
*/
@XmlElement(name = "out_return_no")
@JSONField(name = "out_return_no")
private String outReturnNo;
/**
* 回退方类型
*/
@XmlElement(name = "return_account_type")
@JSONField(name = "return_account_type")
private ReturnAccountType returnAccountType = ReturnAccountType.MERCHANT_ID;
/**
* 回退方账号
* 当回退方类型为商户ID时填写商户ID
*/
@XmlElement(name = "return_account")
@JSONField(name = "return_account")
private String returnAccount;
/**
* 回退描述
*/
private String description;
/**
* 用于回退查询的参数构造方法
*
* @param orderId
* 微信分帐单号
* @param outOrderNo
* 商户分帐单号
* @param outReturnNo
* 商户回退单号
*/
public ProfitSharingReturnRequest(String orderId, String outOrderNo, String outReturnNo) {
this.orderId = orderId;
this.outOrderNo = outOrderNo;
this.outReturnNo = outReturnNo;
}
/**
* 用于回退请求的参数构造方法
*
* @param orderId
* 微信分帐单号
* @param outOrderNo
* 商户分帐单号
* @param outReturnNo
* 商户回退单号
* @param returnAccountType
* 回退方类型
* @param returnAccount
* 回退方帐号
* @param description
* 回退描述
*/
public ProfitSharingReturnRequest(String orderId, String outOrderNo, String outReturnNo,
ReturnAccountType returnAccountType, String returnAccount, String description) {
this.orderId = orderId;
this.outOrderNo = outOrderNo;
this.outReturnNo = outReturnNo;
this.returnAccountType = returnAccountType;
this.returnAccount = returnAccount;
this.description = description;
}
@Override
public String getSignType() {
return signType;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getOutOrderNo() {
return outOrderNo;
}
public void setOutOrderNo(String outOrderNo) {
this.outOrderNo = outOrderNo;
}
public String getOutReturnNo() {
return outReturnNo;
}
public void setOutReturnNo(String outReturnNo) {
this.outReturnNo = outReturnNo;
}
public ReturnAccountType getReturnAccountType() {
return returnAccountType;
}
public void setReturnAccountType(ReturnAccountType returnAccountType) {
this.returnAccountType = returnAccountType;
}
public String getReturnAccount() {
return returnAccount;
}
public void setReturnAccount(String returnAccount) {
this.returnAccount = returnAccount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,167 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
import javax.xml.bind.annotation.XmlElement;
/**
* 分帐回退/回退查询返回内容
*
* @author kitkit.li@qq.com
* @date 2020年05年25日
* @since weixin4j-pay 1.1.0
*/
public class ProfitSharingReturnResult extends MerchantResult {
/**
* 微信分账单号
*/
@XmlElement(name = "order_id")
@JSONField(name = "order_id")
private String orderId;
/**
* 商户分账单号
*/
@XmlElement(name = "out_order_no")
@JSONField(name = "out_order_no")
private String outOrderNo;
/**
* 商户回退单号
*/
@XmlElement(name = "out_return_no")
@JSONField(name = "out_return_no")
private String outReturnNo;
/**
* 微信回退单号
*/
@XmlElement(name = "return_no")
@JSONField(name = "return_no")
private String returnNo;
/**
* 回退方类型
*/
@XmlElement(name = "return_account_type")
@JSONField(name = "return_account_type")
private ReturnAccountType returnAccountType;
/**
* 回退方账号
*/
@XmlElement(name = "return_account")
@JSONField(name = "return_account")
private String returnAccount;
/**
* 回退金额
*/
@XmlElement(name = "return_amount")
@JSONField(name = "return_amount")
private Integer returnAmount;
/**
* 回退描述
*/
private String description;
/**
* 回退结果
*/
private String result;
/**
* 失败原因
*/
@XmlElement(name = "fail_reason")
@JSONField(name = "fail_reason")
private String failReason;
/**
* 完成时间
*/
@XmlElement(name = "finish_time")
@JSONField(name = "finish_time")
private String finishTime;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getOutOrderNo() {
return outOrderNo;
}
public void setOutOrderNo(String outOrderNo) {
this.outOrderNo = outOrderNo;
}
public String getOutReturnNo() {
return outReturnNo;
}
public void setOutReturnNo(String outReturnNo) {
this.outReturnNo = outReturnNo;
}
public String getReturnNo() {
return returnNo;
}
public void setReturnNo(String returnNo) {
this.returnNo = returnNo;
}
public ReturnAccountType getReturnAccountType() {
return returnAccountType;
}
public void setReturnAccountType(ReturnAccountType returnAccountType) {
this.returnAccountType = returnAccountType;
}
public String getReturnAccount() {
return returnAccount;
}
public void setReturnAccount(String returnAccount) {
this.returnAccount = returnAccount;
}
public Integer getReturnAmount() {
return returnAmount;
}
public void setReturnAmount(Integer returnAmount) {
this.returnAmount = returnAmount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getFailReason() {
return failReason;
}
public void setFailReason(String failReason) {
this.failReason = failReason;
}
public String getFinishTime() {
return finishTime;
}
public void setFinishTime(String finishTime) {
this.finishTime = finishTime;
}
}

View File

@ -0,0 +1,101 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReceiverType;
import com.foxinmy.weixin4j.pay.type.profitsharing.RelationType;
/**
* 分账接收方基础信息
* 用于添加或删除分帐接收方时使用
*
* @author kit(kit_21cn@21cn.com)
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public class Receiver {
public Receiver(ReceiverType type, String account) {
this.type = type;
this.account = account;
this.relationType = null;
}
public Receiver(ReceiverType type, String account, RelationType relationType) {
this.type = type;
this.account = account;
this.relationType = relationType;
}
/**
* 分账接收方类型
*/
private ReceiverType type;
/**
* 分账接收方帐号
* 类型是MERCHANT_ID时是商户ID
* 类型是PERSONAL_WECHATID时是个人微信号
* 类型是PERSONAL_OPENID时是个人openid
* 类型是PERSONAL_SUB_OPENID时是个人sub_openid
*/
private String account;
/**
* 分账接收方全称
* 分账接收方类型是MERCHANT_ID时是商户全称必传
* 分账接收方类型是PERSONAL_WECHATID 是个人姓名必传
* 分账接收方类型是PERSONAL_OPENID时是个人姓名选传传则校验
* 分账接收方类型是PERSONAL_SUB_OPENID时是个人姓名选传传则校验
*/
private String name;
/**
* 与分账方的关系类型
*/
@JSONField(name = "relation_type")
private RelationType relationType;
/**
* 自定义的分账关系
* 子商户与接收方具体的关系本字段最多10个字
* 当字段relation_type的值为CUSTOM时本字段必填
*/
@JSONField(name = "custom_relation")
private String customRelation;
public ReceiverType getType() {
return type;
}
public void setType(ReceiverType type) {
this.type = type;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public RelationType getRelationType() {
return relationType;
}
public void setRelationType(RelationType relationType) {
this.relationType = relationType;
}
public String getCustomRelation() {
return customRelation;
}
public void setCustomRelation(String customRelation) {
this.customRelation = customRelation;
}
}

View File

@ -0,0 +1,37 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReceiverType;
/**
* 请求分帐时使用的分帐方信息
*
* @author kit(kit.li@qq.com)
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public class ReceiverProfit extends Receiver {
private int amount;
private String description;
public ReceiverProfit(ReceiverType type, String account, int amount, String description){
super(type, account);
this.amount = amount;
this.description = description;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,63 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReceiverType;
import javax.xml.bind.annotation.XmlElement;
/**
* 分帐方添加删除API调用结果
*
* @author kit (kit.li@qq.com)
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public class ReceiverProfitResult extends ReceiverProfit {
/**
* 分帐结果
* PENDING:待分账
* SUCCESS:分账成功
* ADJUST:分账失败待调账
* RETURNED:已转回分账方
* CLOSED: 已关闭
*/
private String result;
/**
* 分账完成时间
*/
@XmlElement(name = "finish_time")
@JSONField(name = "finish_time")
private String finishTime;
@XmlElement(name = "fail_reason")
@JSONField(name = "fail_reason")
private String failReason;
public ReceiverProfitResult(ReceiverType type, String account, int amount, String description, String result){
super(type, account, amount, description);
this.result = result;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String getFinishTime() {
return finishTime;
}
public void setFinishTime(String finishTime) {
this.finishTime = finishTime;
}
public String getFailReason() {
return failReason;
}
public void setFailReason(String failReason) {
this.failReason = failReason;
}
}

View File

@ -0,0 +1,41 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
import javax.xml.bind.annotation.XmlElement;
/**
* 分帐方添加及删除的API请求
*
* @author kit (kit.li@qq.com)
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public class ReceiverRequest extends MerchantResult {
@XmlElement(name = "sign_type")
@JSONField(name = "sign_type")
private final String signType = "HMAC-SHA256";
public ReceiverRequest(Receiver receiver){
super();
this.receiver = JSON.toJSONString(receiver);
}
private String receiver;
public String getReceiver() {
return this.receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
@Override
public String getSignType() {
return signType;
}
}

View File

@ -0,0 +1,38 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
/**
* 微信支付-服务商分帐接口-分帐接收方API返回结果
*
* @author kit(kit_21cn@21cn.com)
* @className ProfitSharingReceiverResult
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public class ReceiverResult extends MerchantResult {
/**
* 分账接收方对象json格式字符串
*/
private String receiver;
public String getReceiver() {
return receiver;
}
public void setReceiver(String receiver) {
this.receiver = receiver;
}
/**
* 返回接收方java对象
*/
public Receiver getReceiverObject(){
try {
return JSON.parseObject(receiver, Receiver.class);
} catch (Exception e) {
return null;
}
}
}

View File

@ -0,0 +1,19 @@
package com.foxinmy.weixin4j.pay.type;
/**
* 分帐单号类型
*
* @author kit (kit.li@qq.com)
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public enum ProfitIdType {
/**
* 微信分帐单号
*/
ORDER_ID,
/**
* 商户分帐单号
*/
OUT_ORDER_NO
}

View File

@ -0,0 +1,19 @@
package com.foxinmy.weixin4j.pay.type;
/**
* 通用的是或否参数
*
* @author kit (kit.li@qq.com)
* @date 2020年05月22日
* @since weixin4j-pay 1.1.0
*/
public enum YesNoType {
/**
*
*/
Y,
/**
*
*/
N
}

View File

@ -1,20 +0,0 @@
package com.foxinmy.weixin4j.pay.type.mch;
/**
* 是否押金支付
*
* @className DepositType
* @author kit(kit_21cn@21cn.com)
* @date 2019年9月21日
* @since JDK 1.6
*/
public enum DepositType {
/**
*
*/
Y,
/**
*
*/
N;
}

View File

@ -0,0 +1,27 @@
package com.foxinmy.weixin4j.pay.type.profitsharing;
/**
* 分帐接收方类型
*
* @author kit (kit.li@qq.com)
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public enum ReceiverType {
/**
* 商户ID
*/
MERCHANT_ID,
/**
* 个人微信号
*/
PERSONAL_WECHATID,
/**
* 个人微信openid
*/
PERSONAL_OPENID,
/**
* 个人微信sub_openid (对应服务商API的子商户sub_appid转换得到)
*/
PERSONAL_SUB_OPENID;
}

View File

@ -0,0 +1,55 @@
package com.foxinmy.weixin4j.pay.type.profitsharing;
/**
* 子商户与接收方的关系
*
* @author kit (kit.li@qq.com)
* @date 2020年05月20日
* @since weixin4j-pay 1.1.0
*/
public enum RelationType {
/**
* 服务商
*/
SERVICE_PROVIDER,
/**
* 门店
*/
STORE,
/**
* 员工
*/
STAFF,
/**
* 店主
*/
STORE_OWNER,
/**
* 合作伙伴
*/
PARTNER,
/**
* 总部
*/
HEADQUARTER,
/**
* 品牌方
*/
BRAND,
/**
* 分销商
*/
DISTRIBUTOR,
/**
* 用户
*/
USER,
/**
* 供应商
*/
SUPPLIER,
/**
* 自定义
*/
CUSTOM;
}

View File

@ -0,0 +1,16 @@
package com.foxinmy.weixin4j.pay.type.profitsharing;
/**
* 分帐回退的回退方类型
*
* @author kit
* @date 2020年05月25日
* @since weixin4j-pay 1.1.0
*/
public enum ReturnAccountType {
/**
* 商户ID
* 目前仅支付商户接收方的回退
*/
MERCHANT_ID
}

View File

@ -62,3 +62,19 @@ facepay_url={mch_base_url}/pay/facepay
deposit_facepay_uri={mch_base_url}/deposit/facepay
# \u652F\u4ED8\u62BC\u91D1\uFF08\u4ED8\u6B3E\u7801\uFF09
deposit_micropay_uri={mch_base_url}/deposit/micropay
# \u670D\u52A1\u5546\u5206\u5E10\u63A5\u53E3--\u6DFB\u52A0\u5206\u8D26\u63A5\u6536\u65B9
profit_sharing_add_receiver_uri={mch_base_url}/pay/profitsharingaddreceiver
# \u670D\u52A1\u5546\u5206\u5E10\u63A5\u53E3--\u5220\u9664\u5206\u8D26\u63A5\u6536\u65B9
profit_sharing_remove_receiver_uri={mch_base_url}/pay/profitsharingremovereceiver
# \u8BF7\u6C42\u5355\u6B21\u5206\u5E10
profit_sharing_uri={mch_base_url}/secapi/pay/profitsharing
# \u8BF7\u6C42\u591A\u6B21\u5206\u5E10
multi_profit_sharing_uri={mch_base_url}/secapi/pay/multiprofitsharing
# \u67E5\u8BE2\u5206\u8D26\u7ED3\u679C
profit_sharing_query_uri={mch_base_url}/pay/profitsharingquery
# \u5206\u5E10\u5B8C\u7ED3
profit_sharing_finish_uri={mch_base_url}/secapi/pay/profitsharingfinish
# \u5206\u5E10\u56DE\u9000
profit_sharing_return_uri={mch_base_url}/secapi/pay/profitsharingreturn
# \u5206\u5E10\u56DE\u9000\u67E5\u8BE2
profit_sharing_return_query_uri={mch_base_url}/pay/profitsharingreturnquery

View File

@ -6,7 +6,6 @@ import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.pay.WeixinPayProxy;
import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
import com.foxinmy.weixin4j.pay.payment.mch.MchPayRequest;
import com.foxinmy.weixin4j.pay.type.mch.DepositType;
import org.junit.Test;
public class TestFacePay {

View File

@ -0,0 +1,53 @@
package com.foxinmy.weixin4j.pay.test;
import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.pay.WeixinPayProxy;
import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
import com.foxinmy.weixin4j.pay.profitsharing.Receiver;
import com.foxinmy.weixin4j.pay.profitsharing.ReceiverResult;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReceiverType;
import com.foxinmy.weixin4j.pay.type.profitsharing.RelationType;
import org.junit.Assert;
import org.junit.Test;
public class TestProfitSharingApi {
// 微信公众号appid
private static String APPID = "wx8208082617097c70";
// 微信支付商户密钥
private static String PAY_SIGN_KEY = "musegogogomusegogogomusegogogo16";
// 商户号
private static String MCHID = "1319061501";
//
private static String OPENID = "oIkWcwtHXPp32ISw_Ept3FUQ1DM4";
/**
* 测试添加分帐方
*/
// @Test
public void testAddReceiver() throws WeixinException {
Receiver receiver = new Receiver(ReceiverType.PERSONAL_OPENID, OPENID, RelationType.STAFF);
WeixinPayAccount account = new WeixinPayAccount(APPID, PAY_SIGN_KEY, MCHID);
WeixinPayProxy proxy = new WeixinPayProxy(account);
ReceiverResult result = proxy.addProfitSharingReceiver(receiver);
System.out.println(JSON.toJSONString(result));
Assert.assertEquals(result.getReturnCode(), "SUCCESS");
}
/**
* 测试删除分帐方
*/
//@Test
public void testRemoveReceiver() throws WeixinException {
Receiver receiver = new Receiver(ReceiverType.PERSONAL_OPENID, OPENID);
WeixinPayAccount account = new WeixinPayAccount(APPID, PAY_SIGN_KEY, MCHID);
WeixinPayProxy proxy = new WeixinPayProxy(account);
ReceiverResult result = proxy.removeProfitSharingReceiver(receiver);
System.out.println(JSON.toJSONString(result));
Assert.assertEquals(result.getReturnCode(), "SUCCESS");
}
public void testProfitPay() throws WeixinException {
}
}