Skip to content

Commit

Permalink
🆕 #1556 增加微信支付或退款回调的时候返回xml字符串方法
Browse files Browse the repository at this point in the history
  • Loading branch information
1ibo authored May 11, 2020
1 parent 8f5a9e0 commit ef7516c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,31 @@ public static String success(String msg) {
return xstream.toXML(response).replace("\n", "").replace(" ", "");
}

/**
* Fail string.
*
* @param msg the msg
* @return the string
*/
public static String failResp(String msg) {
return generateXml(FAIL, msg);
}

/**
* Success string.
*
* @param msg the msg
* @return the string
*/
public static String successResp(String msg) {
return generateXml(SUCCESS, msg);
}


/**
* 使用格式化字符串生成xml字符串
*/
private static String generateXml(String code, String msg) {
return String.format("<xml><return_code><![CDATA[%s]]></return_code><return_msg><![CDATA[%s]]></return_msg></xml>", code, msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@ public void testSuccess() {
"<return_msg><![CDATA[OK]]></return_msg>" +
"</xml>");
}

@Test
public void testSuccessResp() {
final String result = WxPayNotifyResponse.successResp("OK");
assertThat(result).isEqualTo("<xml>" +
"<return_code><![CDATA[SUCCESS]]></return_code>" +
"<return_msg><![CDATA[OK]]></return_msg>" +
"</xml>");
}

@Test
public void testFailResp() {
final String result = WxPayNotifyResponse.failResp("500");
assertThat(result).isEqualTo("<xml>" +
"<return_code><![CDATA[FAIL]]></return_code>" +
"<return_msg><![CDATA[500]]></return_msg>" +
"</xml>");
}
}

0 comments on commit ef7516c

Please sign in to comment.