mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
Merge branch 'master' into develop
# Conflicts: # changelog.md # sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java # sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/HttpTool.java # sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java # sop-test/src/main/java/com/gitee/sop/test/HttpTool.java # sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java
This commit is contained in:
@@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
- 支持预发布、灰度发布环境
|
- 支持预发布、灰度发布环境
|
||||||
|
|
||||||
|
## 1.13.5
|
||||||
|
|
||||||
|
- 修复postJson下version获取不到问题
|
||||||
|
|
||||||
## 1.13.4
|
## 1.13.4
|
||||||
|
|
||||||
- 修复admin服务列表最后更新时间不显示问题
|
- 修复admin服务列表最后更新时间不显示问题
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-registry-api</artifactId>
|
<artifactId>sop-registry-api</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- easyopen starter -->
|
<!-- easyopen starter -->
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>sop-gateway-common</artifactId>
|
<artifactId>sop-gateway-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sop-gateway-common</name>
|
<name>sop-gateway-common</name>
|
||||||
|
@@ -22,4 +22,9 @@ public class GatewayParamBuilder extends BaseParamBuilder<ServerWebExchange> {
|
|||||||
public String getIP(ServerWebExchange ctx) {
|
public String getIP(ServerWebExchange ctx) {
|
||||||
return ctx.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
return ctx.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersionInHeader(ServerWebExchange ctx, String headerName, String version) {
|
||||||
|
ctx.getRequest().getHeaders().add(headerName, version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,14 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
*/
|
*/
|
||||||
public abstract String getIP(T ctx);
|
public abstract String getIP(T ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将版本号添加到header中
|
||||||
|
* @param ctx 请求request
|
||||||
|
* @param headerName headerName
|
||||||
|
* @param version 版本号
|
||||||
|
*/
|
||||||
|
public abstract void setVersionInHeader(T ctx, String headerName, String version);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiParam build(T ctx) {
|
public ApiParam build(T ctx) {
|
||||||
ApiParam apiParam = this.newApiParam(ctx);
|
ApiParam apiParam = this.newApiParam(ctx);
|
||||||
@@ -38,6 +46,7 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
apiParam.putAll(requestParams);
|
apiParam.putAll(requestParams);
|
||||||
this.initOtherProperty(apiParam);
|
this.initOtherProperty(apiParam);
|
||||||
apiParam.setIp(this.getIP(ctx));
|
apiParam.setIp(this.getIP(ctx));
|
||||||
|
this.setVersionInHeader(ctx, ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion());
|
||||||
return apiParam;
|
return apiParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,7 +45,7 @@ public class ParamNames {
|
|||||||
/** 返回sign名称 */
|
/** 返回sign名称 */
|
||||||
public static String RESPONSE_SIGN_NAME = "sign";
|
public static String RESPONSE_SIGN_NAME = "sign";
|
||||||
|
|
||||||
public static String GRAY_HEADER_VERSION_NAME = "sop_gray_version";
|
public static String HEADER_VERSION_NAME = "sop-version";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -52,6 +52,11 @@ public class ZuulParamBuilder extends BaseParamBuilder<RequestContext> {
|
|||||||
return RequestUtil.getIP(ctx.getRequest());
|
return RequestUtil.getIP(ctx.getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersionInHeader(RequestContext ctx, String headerName, String version) {
|
||||||
|
ctx.addZuulRequestHeader(headerName, version);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ApiParam newApiParam(RequestContext ctx) {
|
protected ApiParam newApiParam(RequestContext ctx) {
|
||||||
ApiParam apiParam = super.newApiParam(ctx);
|
ApiParam apiParam = super.newApiParam(ctx);
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-registry-api</artifactId>
|
<artifactId>sop-registry-api</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package com.gitee.sop.registryapi.bean;
|
package com.gitee.sop.websiteserver.bean;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -110,8 +110,8 @@ public class HttpTool {
|
|||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public String request(String url, Map<String, ?> form, Map<String, String> header, HTTPMethod 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.value());
|
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
|
||||||
// 添加header
|
// 添加header
|
||||||
addHeader(requestBuilder, header);
|
addHeader(requestBuilder, header);
|
||||||
|
|
||||||
@@ -153,21 +153,21 @@ public class HttpTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Request.Builder buildRequestBuilder(String url, Map<String, ?> form, String method) {
|
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "get":
|
case GET:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.get();
|
.get();
|
||||||
case "head":
|
case HEAD:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.head();
|
.head();
|
||||||
case "put":
|
case PUT:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.put(buildFormBody(form));
|
.put(buildFormBody(form));
|
||||||
case "delete":
|
case DELETE:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.delete(buildFormBody(form));
|
.delete(buildFormBody(form));
|
||||||
@@ -178,18 +178,18 @@ public class HttpTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl buildHttpUrl(String url, Map<String, ?> form) {
|
public static HttpUrl buildHttpUrl(String url, Map<String, String> form) {
|
||||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
||||||
for (Map.Entry<String, ?> entry : form.entrySet()) {
|
for (Map.Entry<String, String> entry : form.entrySet()) {
|
||||||
urlBuilder.addQueryParameter(entry.getKey(), String.valueOf(entry.getValue()));
|
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return urlBuilder.build();
|
return urlBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FormBody buildFormBody(Map<String, ?> form) {
|
public static FormBody buildFormBody(Map<String, String> form) {
|
||||||
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
|
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
|
||||||
for (Map.Entry<String, ?> entry : form.entrySet()) {
|
for (Map.Entry<String, String> entry : form.entrySet()) {
|
||||||
paramBuilder.add(entry.getKey(), String.valueOf(entry.getValue()));
|
paramBuilder.add(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return paramBuilder.build();
|
return paramBuilder.build();
|
||||||
}
|
}
|
||||||
|
@@ -6,11 +6,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-common</artifactId>
|
<artifactId>sop-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>sop-service-common</name>
|
<name>sop-service-common</name>
|
||||||
|
@@ -47,5 +47,7 @@ public class ParamNames {
|
|||||||
/** 时间戳格式 */
|
/** 时间戳格式 */
|
||||||
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
public static String HEADER_VERSION_NAME = "sop-version";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -45,11 +45,10 @@ public class ApiMappingRequestCondition implements RequestCondition<ApiMappingRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getVersion(HttpServletRequest request) {
|
protected String getVersion(HttpServletRequest request) {
|
||||||
String versionInHeader = request.getHeader(ParamNames.HEADER_VERSION_NAME);
|
String version = request.getHeader(ParamNames.HEADER_VERSION_NAME);
|
||||||
if (versionInHeader != null) {
|
if (version == null) {
|
||||||
return versionInHeader;
|
version = request.getParameter(ParamNames.VERSION_NAME);
|
||||||
}
|
}
|
||||||
String version = request.getParameter(ParamNames.VERSION_NAME);
|
|
||||||
return version == null ? defaultVersion : version;
|
return version == null ? defaultVersion : version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- eureka 服务发现 -->
|
<!-- eureka 服务发现 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-service-common</artifactId>
|
<artifactId>sop-service-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
|
@@ -30,7 +30,7 @@ public class AlipayController {
|
|||||||
// http://localhost:2222/story_get
|
// http://localhost:2222/story_get
|
||||||
// 原生的接口,可正常调用
|
// 原生的接口,可正常调用
|
||||||
@RequestMapping("story_get")
|
@RequestMapping("story_get")
|
||||||
public Story getStory4() {
|
public Story story_get() {
|
||||||
Story story = new Story();
|
Story story = new Story();
|
||||||
story.setId(1);
|
story.setId(1);
|
||||||
story.setName("海底小纵队(原生)");
|
story.setName("海底小纵队(原生)");
|
||||||
@@ -117,7 +117,7 @@ public class AlipayController {
|
|||||||
// http://localhost:2222/getStory2?version=2.1
|
// http://localhost:2222/getStory2?version=2.1
|
||||||
// 遗留接口具备开放平台能力,在原来的基础上加版本号
|
// 遗留接口具备开放平台能力,在原来的基础上加版本号
|
||||||
@ApiAbility(version = "2.1")
|
@ApiAbility(version = "2.1")
|
||||||
@RequestMapping("getStory2")
|
@GetMapping("getStory2")
|
||||||
public Story getStory2_1() {
|
public Story getStory2_1() {
|
||||||
Story story = new Story();
|
Story story = new Story();
|
||||||
story.setId(1);
|
story.setId(1);
|
||||||
|
@@ -37,5 +37,25 @@ public class PostJsonController {
|
|||||||
return story;
|
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>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-gateway-common</artifactId>
|
<artifactId>sop-gateway-common</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->
|
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->
|
||||||
|
@@ -118,7 +118,7 @@ public class OpenHttp {
|
|||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @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);
|
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
|
||||||
// 添加header
|
// 添加header
|
||||||
addHeader(requestBuilder, 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) {
|
switch (method) {
|
||||||
case "get":
|
case GET:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.get();
|
.get();
|
||||||
case "head":
|
case HEAD:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.head();
|
.head();
|
||||||
case "put":
|
case PUT:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.put(buildFormBody(form));
|
.put(buildFormBody(form));
|
||||||
case "delete":
|
case DELETE:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.delete(buildFormBody(form));
|
.delete(buildFormBody(form));
|
||||||
@@ -241,5 +241,22 @@ public class OpenHttp {
|
|||||||
this.httpClient = httpClient;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,8 +110,8 @@ public class HttpTool {
|
|||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public String request(String url, Map<String, ?> form, Map<String, String> header, HTTPMethod 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.value());
|
Request.Builder requestBuilder = buildRequestBuilder(url, form, method);
|
||||||
// 添加header
|
// 添加header
|
||||||
addHeader(requestBuilder, header);
|
addHeader(requestBuilder, header);
|
||||||
|
|
||||||
@@ -153,21 +153,21 @@ public class HttpTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Request.Builder buildRequestBuilder(String url, Map<String, ?> form, String method) {
|
public static Request.Builder buildRequestBuilder(String url, Map<String, String> form, HTTPMethod method) {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "get":
|
case GET:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.get();
|
.get();
|
||||||
case "head":
|
case HEAD:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(buildHttpUrl(url, form))
|
.url(buildHttpUrl(url, form))
|
||||||
.head();
|
.head();
|
||||||
case "put":
|
case PUT:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.put(buildFormBody(form));
|
.put(buildFormBody(form));
|
||||||
case "delete":
|
case DELETE:
|
||||||
return new Request.Builder()
|
return new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.delete(buildFormBody(form));
|
.delete(buildFormBody(form));
|
||||||
@@ -178,18 +178,18 @@ public class HttpTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl buildHttpUrl(String url, Map<String, ?> form) {
|
public static HttpUrl buildHttpUrl(String url, Map<String, String> form) {
|
||||||
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
||||||
for (Map.Entry<String, ?> entry : form.entrySet()) {
|
for (Map.Entry<String, String> entry : form.entrySet()) {
|
||||||
urlBuilder.addQueryParameter(entry.getKey(), String.valueOf(entry.getValue()));
|
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return urlBuilder.build();
|
return urlBuilder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FormBody buildFormBody(Map<String, ?> form) {
|
public static FormBody buildFormBody(Map<String, String> form) {
|
||||||
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
|
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
|
||||||
for (Map.Entry<String, ?> entry : form.entrySet()) {
|
for (Map.Entry<String, String> entry : form.entrySet()) {
|
||||||
paramBuilder.add(entry.getKey(), String.valueOf(entry.getValue()));
|
paramBuilder.add(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
return paramBuilder.build();
|
return paramBuilder.build();
|
||||||
}
|
}
|
||||||
|
@@ -232,7 +232,7 @@ public class AlipayClientPostTest extends TestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testApiAbility() throws AlipayApiException {
|
public void testGetStory2() throws AlipayApiException {
|
||||||
// 公共请求参数
|
// 公共请求参数
|
||||||
Map<String, String> params = new HashMap<String, String>();
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
params.put("app_id", appId);
|
params.put("app_id", appId);
|
||||||
|
@@ -49,7 +49,41 @@ public class PostJsonTest extends TestBase {
|
|||||||
params.put("sign", sign);
|
params.put("sign", sign);
|
||||||
|
|
||||||
System.out.println("----------- 返回结果 -----------");
|
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);
|
System.out.println(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
<artifactId>sop-registry-api</artifactId>
|
<artifactId>sop-registry-api</artifactId>
|
||||||
<version>1.13.4-SNAPSHOT</version>
|
<version>1.13.5-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Reference in New Issue
Block a user