mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
1.10.1
This commit is contained in:
@@ -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.10.0-SNAPSHOT</version>
|
<version>1.10.1-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.10.0-SNAPSHOT</version>
|
<version>1.10.1-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.10.0-SNAPSHOT</version>
|
<version>1.10.1-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.10.0-SNAPSHOT</version>
|
<version>1.10.1-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.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.gitee.sop</groupId>
|
<groupId>com.gitee.sop</groupId>
|
||||||
|
@@ -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.10.0-SNAPSHOT</version>
|
<version>1.10.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->
|
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->
|
||||||
@@ -31,6 +31,10 @@
|
|||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
|
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.retry</groupId>
|
||||||
|
<artifactId>spring-retry</artifactId>
|
||||||
|
</dependency>
|
||||||
<!-- ↑↑↑ 使用spring cloud zuul ↑↑↑ -->
|
<!-- ↑↑↑ 使用spring cloud zuul ↑↑↑ -->
|
||||||
|
|
||||||
|
|
||||||
|
@@ -14,6 +14,11 @@ zuul:
|
|||||||
# 不用改,如果要改,建议全局替换修改
|
# 不用改,如果要改,建议全局替换修改
|
||||||
secret: MZZOUSTua6LzApIWXCwEgbBmxSzpzC
|
secret: MZZOUSTua6LzApIWXCwEgbBmxSzpzC
|
||||||
|
|
||||||
|
ribbon:
|
||||||
|
# 设置为true(默认false),则所有请求都重试,默认只支持get请求重试
|
||||||
|
# 请谨慎设置,因为post请求大多都是写入请求,如果要支持重试,确保服务的幂等性
|
||||||
|
OkToRetryOnAllOperations: false
|
||||||
|
|
||||||
# 注册中心,根据实际情况修改
|
# 注册中心,根据实际情况修改
|
||||||
eureka:
|
eureka:
|
||||||
serverAddr: localhost:1111
|
serverAddr: localhost:1111
|
||||||
|
@@ -4,17 +4,10 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.gitee.sop.alipay.AlipaySignature;
|
import com.gitee.sop.alipay.AlipaySignature;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模仿支付宝客户端请求接口
|
* 模仿支付宝客户端请求接口
|
||||||
@@ -71,10 +64,11 @@ public class AlipayClientPostTest extends TestBase {
|
|||||||
params.put("sign", sign);
|
params.put("sign", sign);
|
||||||
|
|
||||||
System.out.println("----------- 返回结果 -----------");
|
System.out.println("----------- 返回结果 -----------");
|
||||||
String responseData = post(url, params);// 发送请求
|
String responseData = get(url, params);// 发送请求
|
||||||
System.out.println(responseData);
|
System.out.println(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 这个请求会路由到book服务
|
// 这个请求会路由到book服务
|
||||||
@Test
|
@Test
|
||||||
public void testPostBook() throws Exception {
|
public void testPostBook() throws Exception {
|
||||||
@@ -150,4 +144,38 @@ public class AlipayClientPostTest extends TestBase {
|
|||||||
System.out.println(responseData);
|
System.out.println(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 测试dubbo服务,book会调用story提供的服务。参见:DemoConsumerController.java
|
||||||
|
@Test
|
||||||
|
public void testDubboDemo() throws Exception {
|
||||||
|
// 公共请求参数
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("app_id", appId);
|
||||||
|
params.put("method", "dubbo.story.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", "1.0");
|
||||||
|
|
||||||
|
// 业务参数
|
||||||
|
Map<String, String> bizContent = new HashMap<>();
|
||||||
|
bizContent.put("id", "222");
|
||||||
|
|
||||||
|
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 = post(url, params);// 发送请求
|
||||||
|
System.out.println(responseData);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import org.apache.commons.io.IOUtils;
|
|||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
@@ -78,6 +79,61 @@ public class TestBase extends TestCase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送get请求
|
||||||
|
* @param url
|
||||||
|
* @return JSON或者字符串
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String get(String url, Map<String, String> params) {
|
||||||
|
CloseableHttpClient client = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
try{
|
||||||
|
/**
|
||||||
|
* 创建一个httpclient对象
|
||||||
|
*/
|
||||||
|
client = HttpClients.createDefault();
|
||||||
|
|
||||||
|
List<NameValuePair> nameValuePairs = params.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(entry -> new BasicNameValuePair(entry.getKey(), String.valueOf(entry.getValue())))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
/**
|
||||||
|
* 包装成一个Entity对象
|
||||||
|
*/
|
||||||
|
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
|
||||||
|
//参数转换为字符串
|
||||||
|
String paramsStr = EntityUtils.toString(entity);
|
||||||
|
url = url + "?" + paramsStr;
|
||||||
|
/**
|
||||||
|
* 创建一个post对象
|
||||||
|
*/
|
||||||
|
HttpGet get = new HttpGet(url);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行post请求
|
||||||
|
*/
|
||||||
|
response = client.execute(get);
|
||||||
|
/**
|
||||||
|
* 通过EntityUitls获取返回内容
|
||||||
|
*/
|
||||||
|
// Header[] allHeaders = response.getAllHeaders();
|
||||||
|
// if (allHeaders != null && allHeaders.length > 0) {
|
||||||
|
// System.out.println("----------- headers -----------");
|
||||||
|
// for (Header allHeader : allHeaders) {
|
||||||
|
// System.out.println(allHeader);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
return EntityUtils.toString(response.getEntity(),"UTF-8");
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
IOUtils.closeQuietly(client);
|
||||||
|
IOUtils.closeQuietly(response);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected String buildParamQuery(Map<String, String> params) {
|
protected String buildParamQuery(Map<String, String> params) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Map.Entry<String, String> entry : params.entrySet()) {
|
for (Map.Entry<String, String> entry : params.entrySet()) {
|
||||||
|
Reference in New Issue
Block a user