Skip to content

Commit 91d484f

Browse files
authored
🆕 #1759 微信支付增加电商收付通请求分账接口
* 增加微信收付通请求分账接口
1 parent 6c31059 commit 91d484f

File tree

4 files changed

+282
-0
lines changed

4 files changed

+282
-0
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
import java.io.Serializable;
8+
9+
/**
10+
* 请求分账 对象
11+
* <pre>
12+
* 文档地址:https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml
13+
* </pre>
14+
* @author: f00lish
15+
* @date: 2020/09/12
16+
*/
17+
@Data
18+
@NoArgsConstructor
19+
public class ProfitSharingRequest implements Serializable {
20+
21+
private static final long serialVersionUID = -8662837652326828377L;
22+
/**
23+
* <pre>
24+
* 字段名:公众账号ID
25+
* 变量名:appid
26+
* 是否必填:是
27+
* 类型:string(32)
28+
* 描述:
29+
* 微信分配的公众账号ID。
30+
* 示例值:wx8888888888888888
31+
* </pre>
32+
*/
33+
@SerializedName(value = "appid")
34+
private String appid;
35+
36+
/**
37+
* <pre>
38+
* 字段名:二级商户号
39+
* 变量名:sub_mchid
40+
* 是否必填:是
41+
* 类型:string(32)
42+
* 描述:
43+
* 分账出资的电商平台二级商户,填写微信支付分配的商户号。
44+
* 示例值:1900000109
45+
* </pre>
46+
*/
47+
@SerializedName(value = "sub_mchid")
48+
private String subMchid;
49+
50+
/**
51+
* <pre>
52+
* 字段名:微信订单号
53+
* 变量名:transaction_id
54+
* 是否必填:是
55+
* 类型:string(32)
56+
* 描述:
57+
* 微信支付订单号。
58+
* 示例值:4208450740201411110007820472
59+
* </pre>
60+
*/
61+
@SerializedName(value = "transaction_id")
62+
private String transactionId;
63+
64+
/**
65+
* <pre>
66+
* 字段名:商户分账单号
67+
* 变量名:out_order_no
68+
* 是否必填:是
69+
* 类型:string(64)
70+
* 描述:
71+
* 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
72+
* 示例值:P20150806125346
73+
* </pre>
74+
*/
75+
@SerializedName(value = "out_order_no")
76+
private String outOrderNo;
77+
78+
/**
79+
* <pre>
80+
* 字段名:分账接收方列表
81+
* 变量名:receivers
82+
* 是否必填:是
83+
* 类型:array
84+
* 描述:
85+
* 分账接收方列表,支持设置出资商户作为分账接收方,单次分账最多可有5个分账接收方
86+
* </pre>
87+
*/
88+
@SerializedName(value = "receivers")
89+
private Receiver[] receivers;
90+
91+
/**
92+
* <pre>
93+
* 字段名:是否分账完成
94+
* 变量名:finish
95+
* 是否必填:是
96+
* 类型:bool
97+
* 描述:
98+
* 是否完成分账
99+
* 1、如果为true,该笔订单剩余未分账的金额会解冻回电商平台二级商户;
100+
* 2、如果为false,该笔订单剩余未分账的金额不会解冻回电商平台二级商户,可以对该笔订单再次进行分账。
101+
* 示例值:true
102+
* </pre>
103+
*/
104+
@SerializedName(value = "finish")
105+
private Boolean finish;
106+
107+
@Data
108+
@NoArgsConstructor
109+
public static class Receiver implements Serializable {
110+
111+
private static final long serialVersionUID = 8995144356011793136L;
112+
113+
/**
114+
* <pre>
115+
* 字段名:分账接收方类型
116+
* 变量名:type
117+
* 是否必填:否
118+
* 类型:string(32)
119+
* 描述:
120+
* 分账接收方类型,枚举值:
121+
* MERCHANT_ID:商户
122+
* PERSONAL_OPENID:个人
123+
* 示例值:MERCHANT_ID
124+
* </pre>
125+
*/
126+
@SerializedName(value = "type")
127+
private String type;
128+
129+
/**
130+
* <pre>
131+
* 字段名:分账接收方账号
132+
* 变量名:receiver_account
133+
* 是否必填:是
134+
* 类型:string(32)
135+
* 描述:
136+
* 分账接收方账号:
137+
* 类型是MERCHANT_ID时,是商户ID
138+
* 类型是PERSONAL_OPENID时,是个人openid,openid获取方法 https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/guide/chapter2_1.shtml#menu1
139+
* 示例值:1900000109
140+
* </pre>
141+
*/
142+
@SerializedName(value = "receiver_account")
143+
private String receiverAccount;
144+
145+
/**
146+
* <pre>
147+
* 字段名:分账金额
148+
* 变量名:amount
149+
* 是否必填:是
150+
* 类型:int
151+
* 描述:
152+
* 分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额。
153+
* 示例值:190
154+
* </pre>
155+
*/
156+
@SerializedName(value = "amount")
157+
private Integer amount;
158+
159+
/**
160+
* <pre>
161+
* 字段名:分账描述
162+
* 变量名:description
163+
* 是否必填:是
164+
* 类型:string(180)
165+
* 描述:
166+
* 分账的原因描述,分账账单中需要体现。
167+
* 示例值:分给商户1900000109
168+
* </pre>
169+
*/
170+
@SerializedName(value = "description")
171+
private String description;
172+
173+
/**
174+
* <pre>
175+
* 字段名:分账个人姓名
176+
* 变量名:receiver_name
177+
* 是否必填:否
178+
* 类型:string(10240)
179+
* 描述:
180+
* 可选项,在接收方类型为个人的时可选填,若有值,会检查与 receiver_name 是否实名匹配,不匹配会拒绝分账请求
181+
* 1、分账接收方类型是PERSONAL_OPENID时,是个人姓名的密文(选传,传则校验) 此字段的加密方法详见:敏感信息加密说明
182+
* 2、使用微信支付平台证书中的公钥
183+
* 3、使用RSAES-OAEP算法进行加密
184+
* 4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号
185+
* 示例值:hu89ohu89ohu89o
186+
* </pre>
187+
*/
188+
@SerializedName(value = "receiver_name")
189+
private String receiverName;
190+
191+
}
192+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* 请求分账 结果响应
9+
* @author: f00lish
10+
* @date: 2020/09/12
11+
*/
12+
public class ProfitSharingResult implements Serializable {
13+
14+
private static final long serialVersionUID = 9026456165403642050L;
15+
/**
16+
* <pre>
17+
* 字段名:二级商户号
18+
* 变量名:sub_mchid
19+
* 是否必填:是
20+
* 类型:string(32)
21+
* 描述:
22+
* 分账出资的电商平台二级商户,填写微信支付分配的商户号。
23+
* 示例值:1900000109
24+
* </pre>
25+
*/
26+
@SerializedName(value = "sub_mchid")
27+
private String subMchid;
28+
29+
/**
30+
* <pre>
31+
* 字段名:微信订单号
32+
* 变量名:transaction_id
33+
* 是否必填:是
34+
* 类型:string(32)
35+
* 描述:
36+
* 微信支付订单号。
37+
* 示例值:4208450740201411110007820472
38+
* </pre>
39+
*/
40+
@SerializedName(value = "transaction_id")
41+
private String transactionId;
42+
43+
/**
44+
* <pre>
45+
* 字段名:商户分账单号
46+
* 变量名:out_order_no
47+
* 是否必填:是
48+
* 类型:string(64)
49+
* 描述:
50+
* 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。
51+
* 示例值:P20150806125346
52+
* </pre>
53+
*/
54+
@SerializedName(value = "out_order_no")
55+
private String outOrderNo;
56+
57+
/**
58+
* <pre>
59+
* 字段名:微信分账单号
60+
* 变量名:order_id
61+
* 是否必填:是
62+
* 类型:string (64)
63+
* 描述:
64+
* 微信分账单号,微信系统返回的唯一标识。
65+
* 示例值:6754760740201411110007865434
66+
* </pre>
67+
*/
68+
@SerializedName(value = "order_id")
69+
private String orderId;
70+
71+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,16 @@ public interface EcommerceService {
174174
* @return 返回数据
175175
*/
176176
FundBalanceResult subDayEndBalance(String subMchid, String date) throws WxPayException;
177+
178+
/**
179+
* <pre>
180+
* 请求分账API
181+
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_1.shtml
182+
* </pre>
183+
*
184+
* @param request 分账请求
185+
* @return 返回数据
186+
*/
187+
ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;
188+
177189
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ public FundBalanceResult subDayEndBalance(String subMchid, String date) throws W
148148
return GSON.fromJson(response, FundBalanceResult.class);
149149
}
150150

151+
@Override
152+
public ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException {
153+
String url = String.format("%s/v3/ecommerce/profitsharing/orders", this.payService.getPayBaseUrl());
154+
String response = this.payService.postV3(url, GSON.toJson(request));
155+
return GSON.fromJson(response, ProfitSharingResult.class);
156+
}
157+
151158
private boolean verifyNotifySign(SignatureHeader header, String data) {
152159
String beforeSign = String.format("%s\n%s\n%s\n",
153160
header.getTimeStamp(),

0 commit comments

Comments
 (0)