From ef7516c191ad163abb0a6ba4e752aeda0eb96f65 Mon Sep 17 00:00:00 2001 From: 1ibo <422423229@qq.com> Date: Mon, 11 May 2020 17:45:28 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1556=20=E5=A2=9E=E5=8A=A0=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E6=94=AF=E4=BB=98=E6=88=96=E9=80=80=E6=AC=BE=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E7=9A=84=E6=97=B6=E5=80=99=E8=BF=94=E5=9B=9Exml?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/notify/WxPayNotifyResponse.java | 27 +++++++++++++++++++ .../bean/notify/WxPayNotifyResponseTest.java | 18 +++++++++++++ 2 files changed, 45 insertions(+) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java index ed1353284..3b1cfe7a8 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponse.java @@ -60,4 +60,31 @@ public class WxPayNotifyResponse { 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("", code, msg); + } } diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java index 1baaa8ead..60be34e35 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayNotifyResponseTest.java @@ -20,4 +20,22 @@ public class WxPayNotifyResponseTest { "" + ""); } + + @Test + public void testSuccessResp() { + final String result = WxPayNotifyResponse.successResp("OK"); + assertThat(result).isEqualTo("" + + "" + + "" + + ""); + } + + @Test + public void testFailResp() { + final String result = WxPayNotifyResponse.failResp("500"); + assertThat(result).isEqualTo("" + + "" + + "" + + ""); + } }