Skip to content

Commit 6472484

Browse files
authored
🆕 #2501【微信支付】增加V3版本回调通知应答
1 parent c84b46a commit 6472484

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.binarywang.wxpay.bean.notify;
2+
3+
import com.google.gson.Gson;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
/**
10+
* 微信支付订单和退款的异步通知,V3版本共用的响应类.
11+
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_11.shtml
12+
*
13+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
14+
* @date 2022-08-15
15+
*/
16+
@Data
17+
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
public class WxPayNotifyV3Response {
21+
22+
private static final transient String SUCCESS = "SUCCESS";
23+
private static final transient String FAIL = "FAIL";
24+
25+
private String code;
26+
private String message;
27+
28+
/**
29+
* 返回成功
30+
*
31+
* @param msg
32+
* @return
33+
*/
34+
public static String success(String msg) {
35+
WxPayNotifyV3Response response = new WxPayNotifyV3Response(SUCCESS, msg);
36+
return new Gson().toJson(response);
37+
}
38+
39+
/**
40+
* 返回失败
41+
*
42+
* @param msg 返回信息,如非空,为错误原因
43+
* @return
44+
*/
45+
public static String fail(String msg) {
46+
WxPayNotifyV3Response response = new WxPayNotifyV3Response(FAIL, msg);
47+
return new Gson().toJson(response);
48+
}
49+
50+
}

Diff for: weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java

+15
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public static class RefundStatus {
311311
public static final String SUCCESS = "SUCCESS";
312312

313313
/**
314+
* v2
314315
* 退款关闭.
315316
*/
316317
public static final String REFUND_CLOSE = "REFUNDCLOSE";
@@ -321,10 +322,23 @@ public static class RefundStatus {
321322
public static final String PROCESSING = "PROCESSING";
322323

323324
/**
325+
* v2
324326
* 退款异常.
325327
* 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
326328
*/
327329
public static final String CHANGE = "CHANGE";
330+
331+
/**
332+
* v3
333+
* 退款关闭
334+
*/
335+
public static final String CLOSED = "CLOSED";
336+
337+
/**
338+
* v3
339+
* 退款异常
340+
*/
341+
public static final String ABNORMAL = "ABNORMAL";
328342
}
329343

330344
public static class ReceiverType {
@@ -345,4 +359,5 @@ public static class ReceiverType {
345359
*/
346360
public static final String PERSONAL_SUB_OPENID = "PERSONAL_SUB_OPENID";
347361
}
362+
348363
}

Diff for: weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.binarywang.wxpay.bean.notify;
22

3+
import lombok.extern.slf4j.Slf4j;
34
import org.testng.annotations.Test;
45

56
import static org.assertj.core.api.Assertions.assertThat;
@@ -10,8 +11,12 @@
1011
* @author <a href="https://github.com/binarywang">Binary Wang</a>
1112
* @date 2019-06-30
1213
*/
14+
@Slf4j
1315
public class WxPayNotifyResponseTest {
1416

17+
/**
18+
* V2版本
19+
*/
1520
@Test
1621
public void testSuccess() {
1722
final String result = WxPayNotifyResponse.success("OK");
@@ -38,4 +43,23 @@ public void testFailResp() {
3843
"<return_msg><![CDATA[500]]></return_msg>" +
3944
"</xml>");
4045
}
46+
47+
/**
48+
* V3版本
49+
* https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
50+
*/
51+
@Test
52+
public void testV3Fail() {
53+
final String result = WxPayNotifyV3Response.fail("失败");
54+
log.info(result);
55+
assertThat(result).isNotEmpty();
56+
}
57+
58+
@Test
59+
public void testV3Success() {
60+
final String result = WxPayNotifyV3Response.success("成功");
61+
log.info(result);
62+
assertThat(result).isNotEmpty();
63+
}
64+
4165
}

0 commit comments

Comments
 (0)