File tree 3 files changed +89
-0
lines changed
main/java/com/github/binarywang/wxpay
test/java/com/github/binarywang/wxpay/bean/notify
3 files changed +89
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -311,6 +311,7 @@ public static class RefundStatus {
311
311
public static final String SUCCESS = "SUCCESS" ;
312
312
313
313
/**
314
+ * v2
314
315
* 退款关闭.
315
316
*/
316
317
public static final String REFUND_CLOSE = "REFUNDCLOSE" ;
@@ -321,10 +322,23 @@ public static class RefundStatus {
321
322
public static final String PROCESSING = "PROCESSING" ;
322
323
323
324
/**
325
+ * v2
324
326
* 退款异常.
325
327
* 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台(pay.weixin.qq.com)-交易中心,手动处理此笔退款。
326
328
*/
327
329
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" ;
328
342
}
329
343
330
344
public static class ReceiverType {
@@ -345,4 +359,5 @@ public static class ReceiverType {
345
359
*/
346
360
public static final String PERSONAL_SUB_OPENID = "PERSONAL_SUB_OPENID" ;
347
361
}
362
+
348
363
}
Original file line number Diff line number Diff line change 1
1
package com .github .binarywang .wxpay .bean .notify ;
2
2
3
+ import lombok .extern .slf4j .Slf4j ;
3
4
import org .testng .annotations .Test ;
4
5
5
6
import static org .assertj .core .api .Assertions .assertThat ;
10
11
* @author <a href="https://github.com/binarywang">Binary Wang</a>
11
12
* @date 2019-06-30
12
13
*/
14
+ @ Slf4j
13
15
public class WxPayNotifyResponseTest {
14
16
17
+ /**
18
+ * V2版本
19
+ */
15
20
@ Test
16
21
public void testSuccess () {
17
22
final String result = WxPayNotifyResponse .success ("OK" );
@@ -38,4 +43,23 @@ public void testFailResp() {
38
43
"<return_msg><![CDATA[500]]></return_msg>" +
39
44
"</xml>" );
40
45
}
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
+
41
65
}
You can’t perform that action at this time.
0 commit comments