From 4ed9da77070508303eedef2f8aab1b9f9b3c15e8 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 22 Sep 2020 15:34:35 +0800 Subject: [PATCH] 4.0.3 --- .../Example1001_BaseController.java | 13 +++++ .../controller/result/TestResult.java | 20 +++++++ .../gitee/sop/test/AlipayClientPostTest.java | 2 +- .../java/com/gitee/sop/test/DownloadTest.java | 2 +- .../com/gitee/sop/test/LargeBodyPostTest.java | 2 +- .../com/gitee/sop/test/ParamBindTest.java | 52 +++++++++++++++++++ .../gitee/sop/test/SpringmvcDemoPostTest.java | 2 +- .../sop/test/ThrowExceptionDemoTest.java | 2 +- 8 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TestResult.java diff --git a/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java index 65c18392..31452397 100644 --- a/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/Example1001_BaseController.java @@ -4,15 +4,18 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.gitee.sop.servercommon.annotation.BizCode; import com.gitee.sop.servercommon.annotation.Open; +import com.gitee.sop.servercommon.exception.ServiceException; import com.gitee.sop.storyweb.controller.param.CategoryParam; import com.gitee.sop.storyweb.controller.param.LargeTextParam; import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.result.CategoryResult; import com.gitee.sop.storyweb.controller.result.StoryResult; +import com.gitee.sop.storyweb.controller.result.TestResult; import com.gitee.sop.storyweb.controller.result.TreeResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -107,6 +110,16 @@ public class Example1001_BaseController { return result; } + // 绑定复杂对象 + @Open(value = "sdt.get",version = "4.0") + @RequestMapping("/get/v4") + public TestResult getV4(@RequestBody TestResult testResult) { + if(StringUtils.isEmpty(testResult.getType())) { + throw new ServiceException("testResult.getType() 不能为null"); + } + return testResult; + } + // 返回数组结果 @ApiOperation(value = "返回数组结果(第二)", notes = "返回数组结果", position = -99) @Open("story.list") diff --git a/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TestResult.java b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TestResult.java new file mode 100644 index 00000000..bc0d26f7 --- /dev/null +++ b/sop-example/sop-story/src/main/java/com/gitee/sop/storyweb/controller/result/TestResult.java @@ -0,0 +1,20 @@ +package com.gitee.sop.storyweb.controller.result; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class TestResult { + + @ApiModelProperty(value = "标签", example = "学习") + private String label; + + @ApiModelProperty(value = "类型", example = "1 超管 2 普管") + private String type; + + @ApiModelProperty(value = "集合", example = "集合") + List ss; + +} \ No newline at end of file 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 0c43a1e8..1ab624b0 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 @@ -47,7 +47,7 @@ public class AlipayClientPostTest extends TestBase { params.put("version", "1.0"); // 业务参数 - Map bizContent = new HashMap<>(); + Map bizContent = new HashMap<>(); bizContent.put("id", "1"); bizContent.put("name", "葫芦娃"); diff --git a/sop-test/src/test/java/com/gitee/sop/test/DownloadTest.java b/sop-test/src/test/java/com/gitee/sop/test/DownloadTest.java index d9dcf370..04031e2b 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/DownloadTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/DownloadTest.java @@ -37,7 +37,7 @@ public class DownloadTest extends TestBase { params.put("version", "1.0"); // 业务参数 - Map bizContent = new HashMap<>(); + Map bizContent = new HashMap<>(); bizContent.put("id", "1"); bizContent.put("name", "葫芦娃"); diff --git a/sop-test/src/test/java/com/gitee/sop/test/LargeBodyPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/LargeBodyPostTest.java index 2cf29ef4..ce386a66 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/LargeBodyPostTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/LargeBodyPostTest.java @@ -37,7 +37,7 @@ public class LargeBodyPostTest extends TestBase { params.put("version", "1.0"); // 业务参数 - Map bizContent = new HashMap<>(); + Map bizContent = new HashMap<>(); bizContent.put("id", "1"); String root = System.getProperty("user.dir"); File file = new File(root + "/src/main/resources/large_data.txt"); diff --git a/sop-test/src/test/java/com/gitee/sop/test/ParamBindTest.java b/sop-test/src/test/java/com/gitee/sop/test/ParamBindTest.java index 54c04c2b..9099694a 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/ParamBindTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/ParamBindTest.java @@ -5,8 +5,11 @@ import com.gitee.sop.test.alipay.AlipaySignature; import org.junit.Test; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -53,5 +56,54 @@ public class ParamBindTest extends TestBase { System.out.println(responseData); } + // 绑定复杂对象 + @Test + public void testGet2() throws Exception { + + // 公共请求参数 + Map params = new HashMap(); + params.put("app_id", appId); + params.put("method", "sdt.get"); + params.put("format", "json"); + params.put("charset", "utf-8"); + params.put("sign_type", "RSA2"); + params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + params.put("version", "4.0"); + + // 业务参数 + Map bizContent = new HashMap<>(); + bizContent.put("label", "1"); + bizContent.put("type", "葫芦娃"); + + List> lsm = new ArrayList>(); + Map item = new HashMap<>(); + item.put("label", "11"); + item.put("type", "22"); + lsm.add(item); + + Map item2 = new HashMap<>(); + item2.put("label", "33"); + item2.put("type", "44"); + lsm.add(item2); + + bizContent.put("ss", lsm); + + params.put("biz_content", JSON.toJSONString(bizContent)); + + String content = AlipaySignature.getSignContent(params); + String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); + params.put("sign", sign); + + System.out.println("----------- 请求信息 -----------"); + System.out.println("请求参数:" + buildParamQuery(params)); + System.out.println("商户秘钥:" + privateKey); + System.out.println("待签名内容:" + content); + System.out.println("签名(sign):" + sign); + System.out.println("URL参数:" + buildUrlQuery(params)); + + System.out.println("----------- 返回结果 -----------"); + String responseData = post(url, params);// 发送请求 + System.out.println(responseData); + } } diff --git a/sop-test/src/test/java/com/gitee/sop/test/SpringmvcDemoPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/SpringmvcDemoPostTest.java index b919f948..a551b1e2 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/SpringmvcDemoPostTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/SpringmvcDemoPostTest.java @@ -34,7 +34,7 @@ public class SpringmvcDemoPostTest extends TestBase { params.put("version", "1.0"); // 业务参数 - Map bizContent = new HashMap<>(); + Map bizContent = new HashMap<>(); bizContent.put("goods_name", "iphone6"); params.put("biz_content", JSON.toJSONString(bizContent)); diff --git a/sop-test/src/test/java/com/gitee/sop/test/ThrowExceptionDemoTest.java b/sop-test/src/test/java/com/gitee/sop/test/ThrowExceptionDemoTest.java index 7ce2c041..5b6432e4 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/ThrowExceptionDemoTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/ThrowExceptionDemoTest.java @@ -32,7 +32,7 @@ public class ThrowExceptionDemoTest extends TestBase { params.put("version", "1.0"); // 业务参数 - Map bizContent = new HashMap<>(); + Map bizContent = new HashMap<>(); // 对应校验规则查看GoodsParam.java bizContent.put("goods_name", "1"); bizContent.put("goods_remark", "iphone6");