From e40d885078b019262f0aa71a68a4c39f33f01477 Mon Sep 17 00:00:00 2001 From: tanghc Date: Fri, 4 Dec 2020 09:38:21 +0800 Subject: [PATCH] 4.2.2 --- .../main/java/com/gitee/sop/test/Client.java | 25 +++++++++++++++++-- .../java/com/gitee/sop/test/AllInOneTest.java | 18 +++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/sop-test/src/main/java/com/gitee/sop/test/Client.java b/sop-test/src/main/java/com/gitee/sop/test/Client.java index ec25a65d..1616d669 100644 --- a/sop-test/src/main/java/com/gitee/sop/test/Client.java +++ b/sop-test/src/main/java/com/gitee/sop/test/Client.java @@ -174,6 +174,8 @@ public class Client { public static class RequestBuilder { private static final String DEFAULT_VERSION = "1.0"; + private Map systemParam; + private String url; private String method; private String version = DEFAULT_VERSION; @@ -277,6 +279,20 @@ public class Client { return this; } + /** + * 添加系统参数 + * @param name 参数名 + * @param value 参数值 + * @return 返回RequestBuilder + */ + public RequestBuilder addSystemParam(String name, String value) { + if (systemParam == null) { + systemParam = new HashMap<>(8); + } + systemParam.put(name, value); + return this; + } + /** * 设置token * @@ -376,9 +392,14 @@ public class Client { params.put("charset", "utf-8"); params.put("sign_type", "RSA2"); params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + if (systemParam != null) { + params.putAll(systemParam); + } - // 业务参数 - params.put("biz_content", JSON.toJSONString(bizContent == null ? Collections.emptyMap() : bizContent)); + if (bizContent != null) { + // 业务参数 + params.put("biz_content", JSON.toJSONString(bizContent)); + } if (!ignoreSign) { String content = AlipaySignature.getSignContent(params); diff --git a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java index c8101f38..cbd32462 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java @@ -353,6 +353,24 @@ public class AllInOneTest extends TestBase { client.execute(requestBuilder); } + /** + * 以get方式提交 + */ + public void testBindParam() { + Client.RequestBuilder requestBuilder = new Client.RequestBuilder() + .method("story.param.bind") + .version("1.0") + .addSystemParam("id", "1") + .addSystemParam("name", "葫芦娃") + .httpMethod(HttpTool.HTTPMethod.GET) + .callback(((requestInfo, responseData) -> { + System.out.println(responseData); + Assert.assertTrue(responseData.contains("参数绑定:id:1, name:葫芦娃")); + })); + + client.execute(requestBuilder); + } + static class BizContent extends HashMap { public BizContent add(String key, Object value) { this.put(key, value);