Skip to content

Commit ef7516c

Browse files
authored
🆕 #1556 增加微信支付或退款回调的时候返回xml字符串方法
1 parent 8f5a9e0 commit ef7516c

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,31 @@ public static String success(String msg) {
6060
return xstream.toXML(response).replace("\n", "").replace(" ", "");
6161
}
6262

63+
/**
64+
* Fail string.
65+
*
66+
* @param msg the msg
67+
* @return the string
68+
*/
69+
public static String failResp(String msg) {
70+
return generateXml(FAIL, msg);
71+
}
72+
73+
/**
74+
* Success string.
75+
*
76+
* @param msg the msg
77+
* @return the string
78+
*/
79+
public static String successResp(String msg) {
80+
return generateXml(SUCCESS, msg);
81+
}
82+
83+
84+
/**
85+
* 使用格式化字符串生成xml字符串
86+
*/
87+
private static String generateXml(String code, String msg) {
88+
return String.format("<xml><return_code><![CDATA[%s]]></return_code><return_msg><![CDATA[%s]]></return_msg></xml>", code, msg);
89+
}
6390
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,22 @@ public void testSuccess() {
2020
"<return_msg><![CDATA[OK]]></return_msg>" +
2121
"</xml>");
2222
}
23+
24+
@Test
25+
public void testSuccessResp() {
26+
final String result = WxPayNotifyResponse.successResp("OK");
27+
assertThat(result).isEqualTo("<xml>" +
28+
"<return_code><![CDATA[SUCCESS]]></return_code>" +
29+
"<return_msg><![CDATA[OK]]></return_msg>" +
30+
"</xml>");
31+
}
32+
33+
@Test
34+
public void testFailResp() {
35+
final String result = WxPayNotifyResponse.failResp("500");
36+
assertThat(result).isEqualTo("<xml>" +
37+
"<return_code><![CDATA[FAIL]]></return_code>" +
38+
"<return_msg><![CDATA[500]]></return_msg>" +
39+
"</xml>");
40+
}
2341
}

0 commit comments

Comments
 (0)