Skip to content

Commit bdafa81

Browse files
linyaqiangbinarywang
authored andcommitted
🎨 【微信支付】增加服务商模式下分账通知的解析方法
1 parent 3576f53 commit bdafa81

3 files changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package com.github.binarywang.wxpay.bean.profitsharing.v3;
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+
* 微信V3接口-服务商
12+
* 分账动账通知解密后数据实体
13+
*
14+
* @author linyaqiang
15+
* @since 2023-08-01
16+
*/
17+
@Data
18+
@NoArgsConstructor
19+
public class ProfitSharingPartnerNotifyResult implements Serializable {
20+
private static final long serialVersionUID = -2875006651351414624L;
21+
22+
/**
23+
* <pre>
24+
* 字段名:服务商商户号
25+
* 是否必填:是
26+
* 描述:服务商模式分账发起商户。
27+
* </pre>
28+
*/
29+
@SerializedName("sp_mchid")
30+
private String spMchid;
31+
32+
/**
33+
* <pre>
34+
* 字段名:子商户号
35+
* 是否必填:是
36+
* 描述:服务商模式分账出资商户。
37+
* </pre>
38+
*/
39+
@SerializedName("sub_mchid")
40+
private String subMchid;
41+
42+
/**
43+
* <pre>
44+
* 字段名:微信订单号
45+
* 是否必填:是
46+
* 描述:微信支付订单号
47+
* </pre>
48+
*/
49+
@SerializedName("transaction_id")
50+
private String transactionId;
51+
52+
/**
53+
* <pre>
54+
* 字段名:微信分账/回退单号
55+
* 是否必填:是
56+
* 描述:微信分账/回退单号
57+
* </pre>
58+
*/
59+
@SerializedName("order_id")
60+
private String orderId;
61+
62+
/**
63+
* <pre>
64+
* 字段名:商户分账/回退单号
65+
* 是否必填:是
66+
* 描述:分账方系统内部的分账/回退单号
67+
* </pre>
68+
*/
69+
@SerializedName("out_order_no")
70+
private String outOrderNo;
71+
72+
/**
73+
* <pre>
74+
* 字段名:分账接收方
75+
* 是否必填:是
76+
* 描述:分账接收方对象
77+
* </pre>
78+
*/
79+
@SerializedName("receiver")
80+
private Receiver receiver;
81+
82+
/**
83+
* <pre>
84+
* 字段名:成功时间
85+
* 是否必填:是
86+
* 描述:成功时间,Rfc3339标准
87+
* </pre>
88+
*/
89+
@SerializedName("success_time")
90+
private String successTime;
91+
92+
@Data
93+
@NoArgsConstructor
94+
public static class Receiver implements Serializable {
95+
96+
private static final long serialVersionUID = -931070141604645363L;
97+
98+
/**
99+
* <pre>
100+
* 字段名:分账接收方类型
101+
* 是否必填:是
102+
* 描述:MERCHANT_ID:商户号(mch_id或者sub_mch_id)
103+
* </pre>
104+
*/
105+
@SerializedName("type")
106+
private String type;
107+
108+
/**
109+
* <pre>
110+
* 字段名:分账接收方账号
111+
* 是否必填:是
112+
* 描述:申请本功能商户号
113+
* </pre>
114+
*/
115+
@SerializedName("account")
116+
private String account;
117+
118+
/**
119+
* <pre>
120+
* 字段名:分账动账金额
121+
* 是否必填:是
122+
* 描述:分账动账金额,单位为分,只能为整数
123+
* </pre>
124+
*/
125+
@SerializedName("amount")
126+
private Integer amount;
127+
128+
/**
129+
* <pre>
130+
* 字段名:分账/回退描述
131+
* 是否必填:是
132+
* 描述:分账/回退描述
133+
* </pre>
134+
*/
135+
@SerializedName("description")
136+
private String description;
137+
}
138+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ public interface ProfitSharingV3Service {
240240
*/
241241
ProfitSharingNotifyResult getProfitSharingNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
242242

243+
/**
244+
* <pre>
245+
* 分账动账通知-服务商
246+
*
247+
* 分账或分账回退成功后,微信会把相关变动结果发送给分账接收方(只支持商户)。
248+
* 对后台通知交互时,如果微信收到应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。
249+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter8_1_10.shtml
250+
* </pre>
251+
*
252+
* @param notifyData 分账通知实体
253+
* @param header 分账通知头 {@link SignatureHeader}
254+
* @return {@link ProfitSharingNotifyData} 资源对象
255+
* @throws WxPayException the wx pay exception
256+
* @see <a href="https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter8_1_10.shtml">微信文档</a>
257+
*/
258+
ProfitSharingPartnerNotifyResult getProfitSharingPartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
259+
243260
/**
244261
* <pre>
245262
* 申请分账账单

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ public ProfitSharingNotifyResult getProfitSharingNotifyResult(String notifyData,
135135
}
136136
}
137137

138+
@Override
139+
public ProfitSharingPartnerNotifyResult getProfitSharingPartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
140+
ProfitSharingNotifyData response = parseNotifyData(notifyData, header);
141+
ProfitSharingNotifyData.Resource resource = response.getResource();
142+
String cipherText = resource.getCipherText();
143+
String associatedData = resource.getAssociatedData();
144+
String nonce = resource.getNonce();
145+
String apiV3Key = this.payService.getConfig().getApiV3Key();
146+
try {
147+
String result = AesUtils.decryptToString(associatedData, nonce, cipherText, apiV3Key);
148+
return GSON.fromJson(result, ProfitSharingPartnerNotifyResult.class);
149+
} catch (GeneralSecurityException | IOException e) {
150+
throw new WxPayException("解析报文异常!", e);
151+
}
152+
}
153+
138154
@Override
139155
public ProfitSharingBillResult getProfitSharingBill(ProfitSharingBillRequest request) throws WxPayException {
140156
String url = String.format("%s/v3/profitsharing/bills?bill_date=%s", this.payService.getPayBaseUrl(),

0 commit comments

Comments
 (0)