tanghc 5 years ago
parent e83b0b707a
commit 43bb2efb6a
  1. 2
      sop-admin/sop-admin-server/pom.xml
  2. 2
      sop-common/pom.xml
  3. 4
      sop-common/sop-gateway-common/pom.xml
  4. 2
      sop-common/sop-registry-api/pom.xml
  5. 4
      sop-common/sop-service-common/pom.xml
  6. 2
      sop-example/sop-auth/pom.xml
  7. 2
      sop-example/sop-book/sop-book-web/pom.xml
  8. 2
      sop-example/sop-easyopen/pom.xml
  9. 2
      sop-example/sop-springmvc/pom.xml
  10. 2
      sop-example/sop-story/sop-story-web/pom.xml
  11. 4
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java
  12. 20
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java
  13. 2
      sop-gateway/pom.xml
  14. 29
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java
  15. 12
      sop-test/src/main/java/com/gitee/sop/test/HttpTool.java
  16. 31
      sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java
  17. 36
      sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java
  18. 2
      sop-website/website-server/pom.xml
  19. 15
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java

@ -30,7 +30,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<!-- easyopen starter -->

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>

@ -5,11 +5,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-gateway-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-gateway-common</name>

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

@ -6,11 +6,11 @@
<parent>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<packaging>jar</packaging>
<name>sop-service-common</name>

@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -20,7 +20,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<!-- eureka 服务发现 -->
<dependency>

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -30,7 +30,7 @@ public class AlipayController {
// http://localhost:2222/story_get
// 原生的接口,可正常调用
@RequestMapping("story_get")
public Story getStory4() {
public Story story_get() {
Story story = new Story();
story.setId(1);
story.setName("海底小纵队(原生)");
@ -117,7 +117,7 @@ public class AlipayController {
// http://localhost:2222/getStory2?version=2.1
// 遗留接口具备开放平台能力,在原来的基础上加版本号
@ApiAbility(version = "2.1")
@RequestMapping("getStory2")
@GetMapping("getStory2")
public Story getStory2_1() {
Story story = new Story();
story.setId(1);

@ -37,5 +37,25 @@ public class PostJsonController {
return story;
}
/**
* 演示客户端使用json方式请求application/json
* @param param
* @return
*/
@ApiMapping(value = "demo.post.json", version = "1.2")
public Story postJson2(StoryParam param) {
// 获取开放平台请求参数
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
List<Object> params = Arrays.asList(
openContext.getAppId(),
openContext.getMethod(),
openContext.getVersion()
);
Story story = new Story();
story.setId(1);
story.setName("1.2 参数:" + param.getName() + ", openParams:" + StringUtils.join(params));
return story;
}
}

@ -23,7 +23,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->

@ -118,7 +118,7 @@ public class OpenHttp {
* @return
* @throws IOException
*/
public String request(String url, Map<String, String> form, Map<String, String> header, String method) throws IOException {
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
// 添加header
addHeader(requestBuilder, header);
@ -134,21 +134,21 @@ public class OpenHttp {
}
}
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
switch (method) {
case "get":
case GET:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.get();
case "head":
case HEAD:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.head();
case "put":
case PUT:
return new Request.Builder()
.url(url)
.put(buildFormBody(form));
case "delete":
case DELETE:
return new Request.Builder()
.url(url)
.delete(buildFormBody(form));
@ -241,5 +241,22 @@ public class OpenHttp {
this.httpClient = httpClient;
}
public enum HTTPMethod {
GET,
POST,
PUT,
HEAD,
DELETE;
private HTTPMethod() {
}
public String value() {
return this.name();
}
public static HTTPMethod fromValue(String v) {
return valueOf(v.toUpperCase());
}
}
}

@ -111,7 +111,7 @@ public class HttpTool {
* @throws IOException
*/
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value());
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
// 添加header
addHeader(requestBuilder, header);
@ -153,21 +153,21 @@ public class HttpTool {
}
}
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
switch (method) {
case "get":
case GET:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.get();
case "head":
case HEAD:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.head();
case "put":
case PUT:
return new Request.Builder()
.url(url)
.put(buildFormBody(form));
case "delete":
case DELETE:
return new Request.Builder()
.url(url)
.delete(buildFormBody(form));

@ -231,4 +231,35 @@ public class AlipayClientPostTest extends TestBase {
System.out.println(responseData);
}
@Test
public void testGetStory2() throws AlipayApiException {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);
params.put("method", "getStory2");
params.put("version", "1.0");
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()));
// 业务参数
Map<String, String> bizContent = new HashMap<>();
params.put("biz_content", JSON.toJSONString(bizContent));
System.out.println("----------- 请求信息 -----------");
System.out.println("请求参数:" + buildParamQuery(params));
System.out.println("商户秘钥:" + privateKey);
String content = AlipaySignature.getSignContent(params);
System.out.println("待签名内容:" + content);
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8");
System.out.println("签名(sign):" + sign);
params.put("sign", sign);
System.out.println("----------- 返回结果 -----------");
String responseData = get(url, params);// 发送请求
System.out.println(responseData);
}
}

@ -49,7 +49,41 @@ public class PostJsonTest extends TestBase {
params.put("sign", sign);
System.out.println("----------- 返回结果 -----------");
String responseData = get(url, params);// 发送请求
String responseData = postJson(url, params);// 发送请求
System.out.println(responseData);
}
@Test
public void testPostJson2() throws Exception {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);
params.put("method", "demo.post.json");
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", "1.2");
// 业务参数
Map<String, String> bizContent = new HashMap<>();
bizContent.put("name", "葫芦娃");
params.put("biz_content", JSON.toJSONString(bizContent));
System.out.println("----------- 请求信息 -----------");
System.out.println("请求参数:" + buildParamQuery(params));
System.out.println("商户秘钥:" + privateKey);
String content = AlipaySignature.getSignContent(params);
System.out.println("待签名内容:" + content);
String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8");
System.out.println("签名(sign):" + sign);
params.put("sign", sign);
System.out.println("----------- 返回结果 -----------");
String responseData = postJson(url, params);// 发送请求
System.out.println(responseData);
}

@ -25,7 +25,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>

@ -111,7 +111,7 @@ public class HttpTool {
* @throws IOException
*/
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value());
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
// 添加header
addHeader(requestBuilder, header);
@ -153,21 +153,21 @@ public class HttpTool {
}
}
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
switch (method) {
case "get":
case GET:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.get();
case "head":
case HEAD:
return new Request.Builder()
.url(buildHttpUrl(url, form))
.head();
case "put":
case PUT:
return new Request.Builder()
.url(url)
.put(buildFormBody(form));
case "delete":
case DELETE:
return new Request.Builder()
.url(url)
.delete(buildFormBody(form));
@ -262,6 +262,9 @@ public class HttpTool {
HEAD,
DELETE;
private HTTPMethod() {
}
public String value() {
return this.name();
}

Loading…
Cancel
Save