diff --git a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java index 2dad56e1..67d80f96 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java @@ -56,6 +56,7 @@ public class AlipayClientPostTest extends TestBase { System.out.println("----------- 请求信息 -----------"); System.out.println("请求参数:" + buildParamQuery(params)); + System.out.println("URL参数:" + buildUrlQuery(params)); System.out.println("商户秘钥:" + privateKey); String content = AlipaySignature.getSignContent(params); System.out.println("待签名内容:" + content); diff --git a/sop-test/src/test/java/com/gitee/sop/test/TestBase.java b/sop-test/src/test/java/com/gitee/sop/test/TestBase.java index adbb3538..d6e37210 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/TestBase.java +++ b/sop-test/src/test/java/com/gitee/sop/test/TestBase.java @@ -5,6 +5,8 @@ import junit.framework.TestCase; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Collections; import java.util.Map; @@ -73,4 +75,16 @@ public class TestBase extends TestCase { return sb.toString().substring(1); } + protected static String buildUrlQuery(Map params) { + StringBuilder sb = new StringBuilder(); + for (Map.Entry entry : params.entrySet()) { + try { + sb.append("&").append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(), "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + return sb.toString().substring(1); + } + }