Skip to content

Commit 0d1320a

Browse files
NotePlusbinarywang
authored andcommitted
🆕【微信支付】增加查询结算账户、查询分账结果、查询分账回退结果和申请分账账单等V3接口
1 parent 87c33ac commit 0d1320a

File tree

7 files changed

+220
-6
lines changed

7 files changed

+220
-6
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/applyment/SettlementInfoResult.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
/**
1313
* 查询结算账户返回对象信息
14+
*
15+
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_4.shtml">查询结算账户</a>
1416
*/
1517
@Data
1618
@Builder
@@ -51,4 +53,12 @@ public class SettlementInfoResult implements Serializable {
5153
*/
5254
@SerializedName("verify_result")
5355
private String verifyResult;
56+
/**
57+
* 汇款验证失败原因
58+
*
59+
* @since 4.4.0
60+
* @date 2022.12.09
61+
*/
62+
@SerializedName("verify_fail_reason")
63+
private String verifyFailReason;
5464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.github.binarywang.wxpay.bean.profitsharingV3;
2+
3+
import java.io.Serializable;
4+
5+
import com.google.gson.annotations.SerializedName;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
/**
12+
* 微信V3接口-申请分账账单请求类
13+
*
14+
* @author 狂龙骄子
15+
* @since 4.4.0
16+
* @date 2022-12-09
17+
*/
18+
@Data
19+
@Builder(builderMethodName = "newBuilder")
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
public class ProfitSharingBillRequest implements Serializable {
23+
private static final long serialVersionUID = 5200819754873844593L;
24+
25+
/**
26+
* <pre>
27+
* 字段名:子商户号
28+
* 是否必填:否
29+
* 描述:不填则默认返回服务商下的所有分账账单。如需下载某个子商户下的分账账单,则填指定的子商户号。
30+
* </pre>
31+
*/
32+
@SerializedName("sub_mchid")
33+
private String subMchId;
34+
35+
/**
36+
* <pre>
37+
* 字段名:账单日期
38+
* 是否必填:是
39+
* 描述:格式yyyy-MM-DD,仅支持三个月内的账单下载申请。
40+
* </pre>
41+
*/
42+
@SerializedName("bill_date")
43+
private String billDate;
44+
45+
/**
46+
* <pre>
47+
* 字段名:压缩类型
48+
* 是否必填:否
49+
* 描述:不填则默认是数据流。枚举值:GZIP:返回格式为.gzip的压缩包账单。
50+
* </pre>
51+
*/
52+
@SerializedName("tar_type")
53+
private String tarType;
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.github.binarywang.wxpay.bean.profitsharingV3;
2+
3+
import java.io.Serializable;
4+
5+
import com.google.gson.annotations.SerializedName;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 微信V3接口-申请分账账单结果类
11+
*
12+
* @author 狂龙骄子
13+
* @since 4.4.0
14+
* @date 2022-12-09
15+
*/
16+
@Data
17+
@NoArgsConstructor
18+
public class ProfitSharingBillResult implements Serializable {
19+
private static final long serialVersionUID = -704896948531566657L;
20+
21+
/**
22+
* <pre>
23+
* 字段名:账单下载地址
24+
* 变量名:download_url
25+
* 是否必填:是
26+
* 类型:string[1,2048]
27+
* 描述:
28+
* 供下一步请求账单文件的下载地址,该地址30s内有效。
29+
* 示例值:https://api.mch.weixin.qq.com/v3/bill/downloadurl?token=xxx
30+
* </pre>
31+
*/
32+
@SerializedName(value = "download_url")
33+
private String downloadUrl;
34+
35+
/**
36+
* <pre>
37+
* 字段名:哈希类型
38+
* 变量名:hash_type
39+
* 是否必填:是
40+
* 类型:string[1, 32]
41+
* 描述:
42+
* 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性。
43+
* 示例值:SHA1
44+
* </pre>
45+
*/
46+
@SerializedName(value = "hash_type")
47+
private String hashType;
48+
49+
/**
50+
* <pre>
51+
* 字段名:哈希值
52+
* 变量名:hash_value
53+
* 是否必填:是
54+
* 类型:string[1,1024]
55+
* 描述:
56+
* 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性。
57+
* 示例值:79bb0f45fc4c42234a918000b2668d689e2bde04
58+
* </pre>
59+
*/
60+
@SerializedName(value = "hash_value")
61+
private String hashValue;
62+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/converter/WxPayOrderNotifyResultConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void marshal(Object original, HierarchicalStreamWriter writer, Marshallin
5151
super.marshal(original, writer, context);
5252
WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
5353
List<WxPayOrderNotifyCoupon> list = obj.getCouponList();
54-
if (list == null || list.size() == 0) {
54+
if (list == null || list.isEmpty()) {
5555
return;
5656
}
5757
for (int i = 0; i < list.size(); i++) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public interface Applyment4SubService {
4949
ApplymentStateQueryResult queryApplyStatusByApplymentId(String applymentId) throws WxPayException;
5050

5151
/**
52-
* 通过申请单号查询申请状态
53-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter3_4.shtml
52+
* 根据特约子商户ID查询结算账户
53+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_4.shtml
5454
* 接口链接:https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/settlement
5555
*
5656
* @param subMchid 本服务商进件、已签约的特约商户号。
@@ -61,7 +61,7 @@ public interface Applyment4SubService {
6161

6262
/**
6363
* 修改结算帐号
64-
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/applyment4sub/chapter3_3.shtml
64+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter11_1_3.shtml
6565
* 接口链接:https://api.mch.weixin.qq.com/v3/apply4sub/sub_merchants/{sub_mchid}/modify-settlement
6666
*
6767
* @param subMchid 特约商户号

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

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface ProfitSharingV3Service {
5151

5252
/**
5353
* <pre>
54-
* 查询分账结果API
54+
* 查询分账结果API(商户平台)
5555
*
5656
* 发起分账请求后,可调用此接口查询分账结果
5757
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_2.shtml
@@ -69,6 +69,27 @@ public interface ProfitSharingV3Service {
6969
*/
7070
ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId) throws WxPayException;
7171

72+
/**
73+
* <pre>
74+
* 查询分账结果API(服务商平台)
75+
*
76+
* 发起分账请求后,可调用此接口查询分账结果
77+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_2.shtml
78+
* 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/orders/{out_order_no}
79+
*
80+
* 注意:
81+
* • 发起解冻剩余资金请求后,可调用此接口查询解冻剩余资金的结果
82+
* </pre>
83+
*
84+
* @param outOrderNo 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ 。
85+
* @param transactionId 微信支付订单号
86+
* @param subMchId 微信支付分配的子商户号,即分账的出资商户号。
87+
* @return {@link ProfitSharingResult} 微信返回的分账结果
88+
* @throws WxPayException the wx pay exception
89+
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_2.shtml">微信文档</a>
90+
*/
91+
ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId, String subMchId) throws WxPayException;
92+
7293
/**
7394
* <pre>
7495
* 请求分账回退API
@@ -94,7 +115,7 @@ public interface ProfitSharingV3Service {
94115

95116
/**
96117
* <pre>
97-
* 查询分账回退结果API
118+
* 查询分账回退结果API(商户平台)
98119
*
99120
* 商户需要核实回退结果,可调用此接口查询回退结果
100121
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_4.shtml
@@ -112,6 +133,27 @@ public interface ProfitSharingV3Service {
112133
*/
113134
ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo) throws WxPayException;
114135

136+
/**
137+
* <pre>
138+
* 查询分账回退结果API(服务商平台)
139+
*
140+
* 商户需要核实回退结果,可调用此接口查询回退结果
141+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_3.shtml
142+
* 接口链接:https://api.mch.weixin.qq.com/v3/profitsharing/return-orders/{out_return_no}
143+
*
144+
* 注意:
145+
* • 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果
146+
* </pre>
147+
*
148+
* @param outOrderNo 原发起分账请求时使用的商户系统内部的分账单号
149+
* @param outReturnNo 调用回退接口提供的商户系统内部的回退单号
150+
* @param subMchId 微信支付分配的子商户号,即分账的回退方商户号。
151+
* @return {@link ProfitSharingReturnResult} 微信返回的分账回退结果
152+
* @throws WxPayException the wx pay exception
153+
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_3.shtml">微信文档</a>
154+
*/
155+
ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo, String subMchId) throws WxPayException;
156+
115157
/**
116158
* <pre>
117159
* 解冻剩余资金API
@@ -198,4 +240,21 @@ public interface ProfitSharingV3Service {
198240
*/
199241
ProfitSharingNotifyData getProfitSharingNotifyData(String notifyData, SignatureHeader header) throws WxPayException;
200242

243+
/**
244+
* <pre>
245+
* 申请分账账单
246+
*
247+
* 微信支付按天提供分账账单文件,商户可以通过该接口获取账单文件的下载地址
248+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_11.shtml
249+
* 接口链接: https://api.mch.weixin.qq.com/v3/profitsharing/bills
250+
* </pre>
251+
*
252+
* @param request 申请分账账单请求实体({@link ProfitSharingBillRequest})
253+
* @return {@link ProfitSharingBillResult} 申请分账账单结果类
254+
* @throws WxPayException the wx pay exception
255+
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_11.shtml">服务商平台>>API字典>>资金应用>>分账>>申请分账账单API</a>
256+
* @since 4.4.0
257+
* @date 2022-12-09
258+
*/
259+
ProfitSharingBillResult getProfitSharingBill(ProfitSharingBillRequest request) throws WxPayException;
201260
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.gson.GsonBuilder;
1313
import lombok.RequiredArgsConstructor;
1414
import lombok.extern.slf4j.Slf4j;
15+
import org.apache.commons.lang3.StringUtils;
1516

1617
import java.io.IOException;
1718
import java.nio.charset.StandardCharsets;
@@ -52,6 +53,13 @@ public ProfitSharingResult getProfitSharingResult(String outOrderNo, String tran
5253
return GSON.fromJson(result, ProfitSharingResult.class);
5354
}
5455

56+
@Override
57+
public ProfitSharingResult getProfitSharingResult(String outOrderNo, String transactionId, String subMchId) throws WxPayException {
58+
String url = String.format("%s/v3/profitsharing/orders/%s?sub_mchid=%s&transaction_id=%s", this.payService.getPayBaseUrl(), outOrderNo, subMchId, transactionId);
59+
String result = this.payService.getV3(url);
60+
return GSON.fromJson(result, ProfitSharingResult.class);
61+
}
62+
5563
@Override
5664
public ProfitSharingReturnResult profitSharingReturn(ProfitSharingReturnRequest request) throws WxPayException {
5765
String url = String.format("%s/v3/profitsharing/return-orders", this.payService.getPayBaseUrl());
@@ -67,6 +75,13 @@ public ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo,
6775
return GSON.fromJson(result, ProfitSharingReturnResult.class);
6876
}
6977

78+
@Override
79+
public ProfitSharingReturnResult getProfitSharingReturnResult(String outOrderNo, String outReturnNo, String subMchId) throws WxPayException {
80+
String url = String.format("%s/v3/profitsharing/return-orders/%s?sub_mchid=%s&out_order_no=%s", this.payService.getPayBaseUrl(), outReturnNo, subMchId, outOrderNo);
81+
String result = this.payService.getV3(url);
82+
return GSON.fromJson(result, ProfitSharingReturnResult.class);
83+
}
84+
7085
@Override
7186
public ProfitSharingUnfreezeResult profitSharingUnfreeze(ProfitSharingUnfreezeRequest request) throws WxPayException {
7287
String url = String.format("%s/v3/profitsharing/orders/unfreeze", this.payService.getPayBaseUrl());
@@ -115,6 +130,19 @@ public ProfitSharingNotifyData getProfitSharingNotifyData(String notifyData, Sig
115130
}
116131
}
117132

133+
@Override
134+
public ProfitSharingBillResult getProfitSharingBill(ProfitSharingBillRequest request) throws WxPayException {
135+
String url = String.format("%s/v3/profitsharing/bills?bill_date=%s", this.payService.getPayBaseUrl(), request.getBillDate());
136+
if (StringUtils.isNotBlank(request.getSubMchId())) {
137+
url = String.format("%s&sub_mchid=%s", url, request.getSubMchId());
138+
}
139+
if (StringUtils.isNotBlank(request.getTarType())) {
140+
url = String.format("%s&tar_type=%s", url, request.getTarType());
141+
}
142+
String result = this.payService.getV3(url);
143+
return GSON.fromJson(result, ProfitSharingBillResult.class);
144+
}
145+
118146
private ProfitSharingNotifyData parseNotifyData(String data, SignatureHeader header) throws WxPayException {
119147
if (Objects.nonNull(header) && !this.verifyNotifySign(header, data)) {
120148
throw new WxPayException("非法请求,头部信息验证失败");

0 commit comments

Comments
 (0)