Skip to content

Commit d184ff8

Browse files
w22296437978binarywang
authored andcommitted
#1010 增加微信分账相关接口
* 微信单次分账接口 * - 微信多次分账 - 微信完结分账 - 添加分账接受方 - 删除分账接受方 - 查询分账结果【未能完成单元测试,微信返回签名失败】 - 分账回退【未能完成单元测试,使用真实数据返回“参数不正确”,我对比官方文档除了缺少`sub_mch_id`和`sub_appid`之外其他相同,当我随便填了一个商户id的时候,提示“回退方没有开通分账回退功能”】 - 回退结果查询【未能完成单元测试,因分账回退无法进行,模拟数据返回”记录不存在“】
1 parent 81df397 commit d184ff8

14 files changed

+977
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
import com.thoughtworks.xstream.annotations.XStreamAlias;
7+
import lombok.*;
8+
import me.chanjar.weixin.common.annotation.Required;
9+
10+
/**
11+
* @author Wang GuangXin 2019/10/23 14:02
12+
* @version 1.0
13+
*/
14+
@Data
15+
@EqualsAndHashCode(callSuper = true)
16+
@Builder(builderMethodName = "newBuilder")
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
@XStreamAlias("xml")
20+
public class ProfitSharingFinishRequest extends BaseWxPayRequest {
21+
22+
private static final long serialVersionUID = -4265779954583596627L;
23+
24+
/**
25+
* <pre>
26+
* 字段名:微信订单号.
27+
* 变量名:transaction_id
28+
* 是否必填:是
29+
* String(32)
30+
* 示例值:4208450740201411110007820472
31+
* 描述:微信支付订单号
32+
* </pre>
33+
*/
34+
@XStreamAlias("transaction_id")
35+
@Required
36+
private String transactionId;
37+
38+
/**
39+
* <pre>
40+
* 字段名:商户分账单号.
41+
* 变量名:out_order_no
42+
* 是否必填:是
43+
* String(64)
44+
* 示例值:P20150806125346
45+
* 描述:商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@
46+
* </pre>
47+
*/
48+
@XStreamAlias("out_order_no")
49+
@Required
50+
private String outOrderNo;
51+
52+
/**
53+
* <pre>
54+
* 字段名:分账完结描述.
55+
* 变量名:out_order_no
56+
* 是否必填:是
57+
* String(80)
58+
* 示例值:分账已完成
59+
* 描述:分账完结的原因描述
60+
* </pre>
61+
*/
62+
@XStreamAlias("description")
63+
@Required
64+
private String description;
65+
66+
@Override
67+
protected void checkConstraints() throws WxPayException {
68+
this.setSignType(WxPayConstants.SignType.HMAC_SHA256);
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
import com.thoughtworks.xstream.annotations.XStreamAlias;
7+
import lombok.*;
8+
import me.chanjar.weixin.common.annotation.Required;
9+
10+
/**
11+
* @author Wang GuangXin 2019/10/22 15:44
12+
* @version 1.0
13+
*/
14+
@Data
15+
@EqualsAndHashCode(callSuper = true)
16+
@Builder(builderMethodName = "newBuilder")
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
@XStreamAlias("xml")
20+
public class ProfitSharingQueryRequest extends BaseWxPayRequest {
21+
private static final long serialVersionUID = 3566332883053157102L;
22+
/**
23+
* <pre>
24+
* 字段名:微信支付订单号.
25+
* 变量名:transaction_id
26+
* 是否必填:是
27+
* String(32)
28+
* 示例值:4208450740201411110007820472
29+
* 描述:微信支付订单号
30+
* </pre>
31+
*/
32+
@XStreamAlias("transaction_id")
33+
@Required
34+
private String transactionId;
35+
36+
/**
37+
* <pre>
38+
* 字段名:商户分账单号.
39+
* 变量名:out_order_no
40+
* 是否必填:是
41+
* String(64)
42+
* 示例值:P20150806125346
43+
* 描述:查询分账结果,输入申请分账时的商户分账单号; 查询分账完结的执行结果,输入发起分账完结时的商户分账单号
44+
* </pre>
45+
*/
46+
@XStreamAlias("out_order_no")
47+
@Required
48+
private String outOrderNo;
49+
50+
@Override
51+
protected void checkConstraints() throws WxPayException {
52+
this.setSignType(WxPayConstants.SignType.HMAC_SHA256);
53+
}
54+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
4+
import com.google.gson.FieldNamingPolicy;
5+
import com.google.gson.Gson;
6+
import com.google.gson.GsonBuilder;
7+
import com.thoughtworks.xstream.annotations.XStreamAlias;
8+
import lombok.Data;
9+
import lombok.EqualsAndHashCode;
10+
import lombok.NoArgsConstructor;
11+
12+
/**
13+
* @author Wang GuangXin 2019/10/22 15:51
14+
* @version 1.0
15+
*/
16+
@Data
17+
@EqualsAndHashCode(callSuper = true)
18+
@NoArgsConstructor
19+
@XStreamAlias("xml")
20+
public class ProfitSharingQueryResult extends BaseWxPayResult {
21+
private static final long serialVersionUID = 2548673608075775067L;
22+
/**
23+
* 微信订单号
24+
*/
25+
@XStreamAlias("transaction_id")
26+
private String transactionId;
27+
/**
28+
* 商户分账单号
29+
*/
30+
@XStreamAlias("out_order_no")
31+
private String outOrderNo;
32+
/**
33+
* 微信分账单号
34+
*/
35+
@XStreamAlias("orderId")
36+
private String orderId;
37+
/**
38+
* 分账单状态
39+
*/
40+
@XStreamAlias("status")
41+
private String status;
42+
/**
43+
* 关单原因
44+
*/
45+
@XStreamAlias("close_reason")
46+
private String closeReason;
47+
/**
48+
* 分账接收方列表
49+
*/
50+
@XStreamAlias("receivers")
51+
private String receivers;
52+
/**
53+
* 分账金额
54+
*/
55+
@XStreamAlias("amount")
56+
private Integer amount;
57+
/**
58+
* 分账描述
59+
*/
60+
@XStreamAlias("description")
61+
private String description;
62+
63+
public ProfitSharingQueryResult.Receivers formatReceivers() {
64+
GsonBuilder gsonBuilder = new GsonBuilder();
65+
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
66+
Gson gson = gsonBuilder.create();
67+
return gson.fromJson(receivers, Receivers.class);
68+
}
69+
70+
@Data
71+
public class Receivers {
72+
/**
73+
* 分账接收方类型
74+
*/
75+
private String type;
76+
/**
77+
* 分账接收方帐号
78+
*/
79+
private String account;
80+
/**
81+
* 分账金额
82+
*/
83+
private Integer amount;
84+
/**
85+
* 分账描述
86+
*/
87+
private String description;
88+
/**
89+
* 分账结果
90+
*/
91+
private String result;
92+
/**
93+
* 分账完成时间
94+
*/
95+
private String finishTime;
96+
/**
97+
* 分账失败原因
98+
*/
99+
private String failReason;
100+
101+
@Override
102+
public String toString() {
103+
return "Receivers{" +
104+
"type='" + type + '\'' +
105+
", account='" + account + '\'' +
106+
", amount=" + amount +
107+
", description='" + description + '\'' +
108+
", result='" + result + '\'' +
109+
", finishTime='" + finishTime + '\'' +
110+
", failReason='" + failReason + '\'' +
111+
'}';
112+
}
113+
}
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
import com.thoughtworks.xstream.annotations.XStreamAlias;
7+
import lombok.*;
8+
import me.chanjar.weixin.common.annotation.Required;
9+
10+
/**
11+
* 添加/删除分账接受方请求对象
12+
*
13+
* @author Wang GuangXin 2019/10/22 13:41
14+
* @version 1.0
15+
*/
16+
@Data
17+
@EqualsAndHashCode(callSuper = true)
18+
@Builder(builderMethodName = "newBuilder")
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
@XStreamAlias("xml")
22+
public class ProfitSharingReceiverRequest extends BaseWxPayRequest {
23+
private static final long serialVersionUID = 2628263563539120323L;
24+
/**
25+
* <pre>
26+
* 字段名:分账接收方.
27+
* 变量名:receiver
28+
* 是否必填:是
29+
* String(2048)
30+
* 示例值:{
31+
* "type": "MERCHANT_ID",
32+
* "account": "190001001",
33+
* "name": "示例商户全称",
34+
* "relation_type": "STORE_OWNER"
35+
* }
36+
* 描述:分账接收方对象,json格式
37+
* </pre>
38+
*/
39+
@XStreamAlias("receiver")
40+
@Required
41+
private String receiver;
42+
43+
@Override
44+
protected void checkConstraints() throws WxPayException {
45+
this.setSignType(WxPayConstants.SignType.HMAC_SHA256);
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
4+
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
5+
import com.thoughtworks.xstream.annotations.XStreamAlias;
6+
import lombok.Data;
7+
import lombok.EqualsAndHashCode;
8+
import lombok.NoArgsConstructor;
9+
10+
/**
11+
* @author Wang GuangXin 2019/10/22 14:54
12+
* @version 1.0
13+
*/
14+
@Data
15+
@EqualsAndHashCode(callSuper = true)
16+
@NoArgsConstructor
17+
@XStreamAlias("xml")
18+
public class ProfitSharingReceiverResult extends BaseWxPayResult {
19+
private static final long serialVersionUID = 876204163877798066L;
20+
/**
21+
* 分账接收方.
22+
*/
23+
@XStreamAlias("receiver")
24+
private String receiver;
25+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@NoArgsConstructor
1818
@AllArgsConstructor
1919
@XStreamAlias("xml")
20-
public class ProfitsharingRequest extends BaseWxPayRequest {
20+
public class ProfitSharingRequest extends BaseWxPayRequest {
2121
private static final long serialVersionUID = 212049937430575842L;
2222

2323
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing;
2+
3+
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants;
5+
import com.github.binarywang.wxpay.exception.WxPayException;
6+
import com.thoughtworks.xstream.annotations.XStreamAlias;
7+
import lombok.*;
8+
import me.chanjar.weixin.common.annotation.Required;
9+
import org.apache.commons.lang3.StringUtils;
10+
11+
/**
12+
* @author Wang GuangXin 2019/10/23 15:32
13+
* @version 1.0
14+
*/
15+
@Data
16+
@EqualsAndHashCode(callSuper = true)
17+
@Builder(builderMethodName = "newBuilder")
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@XStreamAlias("xml")
21+
public class ProfitSharingReturnQueryRequest extends BaseWxPayRequest {
22+
private static final long serialVersionUID = -8838464614726086009L;
23+
/**
24+
* <pre>
25+
* 字段名:微信分账单号.
26+
* 变量名:order_id
27+
* 是否必填:二选一
28+
* string(64)
29+
* 示例值:3008450740201411110007820472
30+
* 描述:原发起分账请求时,微信返回的微信分账单号,与商户分账单号一一对应。
31+
* 微信分账单号与商户分账单号二选一填写
32+
* </pre>
33+
*/
34+
@XStreamAlias("order_id")
35+
private String orderId;
36+
37+
/**
38+
* <pre>
39+
* 字段名:商户分账单号.
40+
* 变量名:out_order_no
41+
* 是否必填:二选一
42+
* Sstring(64)
43+
* 示例值:P20180806125346
44+
* 描述:原发起分账请求时使用的商户后台系统的分账单号。
45+
* 微信分账单号与商户分账单号二选一填写
46+
* </pre>
47+
*/
48+
@XStreamAlias("out_order_no")
49+
private String outOrderNo;
50+
51+
/**
52+
* <pre>
53+
* 字段名:商户回退单号.
54+
* 变量名:out_return_no
55+
* 是否必填:是
56+
* string(64)
57+
* 示例值:R20190516001
58+
* 描述:调用回退接口提供的商户系统内部的回退单号
59+
* </pre>
60+
*/
61+
@Required
62+
@XStreamAlias("out_return_no")
63+
private String outReturnNo;
64+
65+
@Override
66+
protected void checkConstraints() throws WxPayException {
67+
if (StringUtils.isBlank(orderId) && StringUtils.isBlank(outOrderNo)) {
68+
throw new WxPayException("order_id 和 outOrderNo 必须有一个存在");
69+
}
70+
this.setSignType(WxPayConstants.SignType.HMAC_SHA256);
71+
}
72+
}

0 commit comments

Comments
 (0)