Skip to content

增加商户处理微信支付或退款回调后同步返回给微信参数的生成方法,通过格式化字符串返回xml字符串结果,避免进行xml对象的转换。 #1556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>");
}
}