mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
Merge branch 'master' into registry-nacos
This commit is contained in:
@@ -1,32 +1,32 @@
|
|||||||
* [首页](/?t=1564057981506)
|
* [首页](/?t=1564370846275)
|
||||||
* 开发文档
|
* 开发文档
|
||||||
* [快速体验](files/10010_快速体验.md?t=1564057981508)
|
* [快速体验](files/10010_快速体验.md?t=1564370846281)
|
||||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1564057981525)
|
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1564370846298)
|
||||||
* [新增接口](files/10020_新增接口.md?t=1564057981525)
|
* [新增接口](files/10020_新增接口.md?t=1564370846298)
|
||||||
* [业务参数校验](files/10030_业务参数校验.md?t=1564057981525)
|
* [业务参数校验](files/10030_业务参数校验.md?t=1564370846299)
|
||||||
* [错误处理](files/10040_错误处理.md?t=1564057981525)
|
* [错误处理](files/10040_错误处理.md?t=1564370846299)
|
||||||
* [编写文档](files/10041_编写文档.md?t=1564057981526)
|
* [编写文档](files/10041_编写文档.md?t=1564370846299)
|
||||||
* [接口交互详解](files/10050_接口交互详解.md?t=1564057981526)
|
* [接口交互详解](files/10050_接口交互详解.md?t=1564370846299)
|
||||||
* [easyopen支持](files/10070_easyopen支持.md?t=1564057981526)
|
* [easyopen支持](files/10070_easyopen支持.md?t=1564370846299)
|
||||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1564057981526)
|
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1564370846299)
|
||||||
* [ISV管理](files/10085_ISV管理.md?t=1564057981526)
|
* [ISV管理](files/10085_ISV管理.md?t=1564370846299)
|
||||||
* [自定义路由](files/10086_自定义路由.md?t=1564057981526)
|
* [自定义路由](files/10086_自定义路由.md?t=1564370846299)
|
||||||
* [路由授权](files/10090_路由授权.md?t=1564057981526)
|
* [路由授权](files/10090_路由授权.md?t=1564370846300)
|
||||||
* [接口限流](files/10092_接口限流.md?t=1564057981526)
|
* [接口限流](files/10092_接口限流.md?t=1564370846300)
|
||||||
* [监控日志](files/10093_监控日志.md?t=1564057981526)
|
* [监控日志](files/10093_监控日志.md?t=1564370846300)
|
||||||
* [SDK开发](files/10095_SDK开发.md?t=1564057981526)
|
* [SDK开发](files/10095_SDK开发.md?t=1564370846300)
|
||||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1564057981526)
|
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1564370846300)
|
||||||
* [应用授权](files/10097_应用授权.md?t=1564057981527)
|
* [应用授权](files/10097_应用授权.md?t=1564370846300)
|
||||||
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1564057981527)
|
* [更改数据节点名称](files/10099_更改数据节点名称.md?t=1564370846300)
|
||||||
* [传统web开发](files/10100_传统web开发.md?t=1564057981527)
|
* [传统web开发](files/10100_传统web开发.md?t=1564370846300)
|
||||||
* [自定义过滤器](files/10102_自定义过滤器.md?t=1564057981527)
|
* [自定义过滤器](files/10102_自定义过滤器.md?t=1564370846300)
|
||||||
* [文件上传](files/10104_文件上传.md?t=1564057981527)
|
* [文件上传](files/10104_文件上传.md?t=1564370846301)
|
||||||
* [nacos注册中心](files/10106_nacos注册中心.md?t=1564057981527)
|
* [nacos注册中心](files/10106_nacos注册中心.md?t=1564370846301)
|
||||||
* [扩展其它注册中心](files/10107_扩展其它注册中心.md?t=1564057981527)
|
* [扩展其它注册中心](files/10107_扩展其它注册中心.md?t=1564370846301)
|
||||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1564057981527)
|
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1564370846301)
|
||||||
* 原理分析
|
* 原理分析
|
||||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1564057981527)
|
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1564370846301)
|
||||||
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1564057981527)
|
* [原理分析之路由存储](files/90011_原理分析之路由存储.md?t=1564370846301)
|
||||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1564057981528)
|
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1564370846301)
|
||||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1564057981528)
|
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1564370846301)
|
||||||
* [常见问题](files/90100_常见问题.md?t=1564057981528)
|
* [常见问题](files/90100_常见问题.md?t=1564370846301)
|
||||||
|
@@ -65,6 +65,33 @@ public Object addGoods(GoodsParam param, HttpServletRequest request) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- 方式2
|
||||||
|
|
||||||
|
```java
|
||||||
|
@ApiMapping(value = "story.get", version = "2.2")
|
||||||
|
public Story getStory22(OpenContext<Story> openContext) {
|
||||||
|
// 业务参数
|
||||||
|
Story bizObject = openContext.getBizObject();
|
||||||
|
// 获取appid,更多方法查看OpenContext类
|
||||||
|
String appId = openContext.getAppId();
|
||||||
|
System.out.println(appId);
|
||||||
|
return bizObject;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
另一种方式,OpenContext泛型参数填bizObject类,调用openContext.getBizObject()可直接获得对象
|
||||||
|
|
||||||
|
此方式等价于:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public Story getStory22(Story bizObject) {
|
||||||
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
|
String appId = openContext.getAppId();
|
||||||
|
System.out.println(appId);
|
||||||
|
return bizObject;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## 接口命名
|
## 接口命名
|
||||||
|
|
||||||
接口命名没有做强制要求,但我们还是推荐按照下面的方式进行命名:
|
接口命名没有做强制要求,但我们还是推荐按照下面的方式进行命名:
|
||||||
|
@@ -11,7 +11,12 @@ String appId = openContext.getAppId();
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
Object bizObject = openContext.getBizObject();
|
Story bizObject = (Story)openContext.getBizObject();
|
||||||
|
|
||||||
|
或
|
||||||
|
|
||||||
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
|
Story bizObject = openContext.getBizObject(Story.class);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Socket error occurred: `localhost/0:0:0:0:0:0:0:1:2181`: Connection refused
|
## Socket error occurred: `localhost/0:0:0:0:0:0:0:1:2181`: Connection refused
|
||||||
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.gitee.sop.servercommon.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tanghc
|
||||||
|
*/
|
||||||
|
public interface OpenBeanFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回业务参数对象
|
||||||
|
*
|
||||||
|
* @param clazz 业务参数类class
|
||||||
|
* @param <T> 业务参数对象
|
||||||
|
* @return 返回业务参数对象
|
||||||
|
*/
|
||||||
|
<T> T getBizObject(Class<T> clazz);
|
||||||
|
}
|
@@ -12,73 +12,84 @@ import java.util.Date;
|
|||||||
* 可通过<code>OpenRequest openRequest = ServiceContext.getCurrentContext().getOpenRequest();</code>方式进行获取
|
* 可通过<code>OpenRequest openRequest = ServiceContext.getCurrentContext().getOpenRequest();</code>方式进行获取
|
||||||
* OpenContext
|
* OpenContext
|
||||||
* OpenParam
|
* OpenParam
|
||||||
* @author tanghc
|
|
||||||
*
|
*
|
||||||
|
* @author tanghc
|
||||||
*/
|
*/
|
||||||
public interface OpenContext<T> {
|
public interface OpenContext<T> extends OpenBeanFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回appid
|
* 返回appid
|
||||||
|
*
|
||||||
* @return 返回appid
|
* @return 返回appid
|
||||||
*/
|
*/
|
||||||
String getAppId();
|
String getAppId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回业务参数json字符串
|
* 返回业务参数json字符串
|
||||||
|
*
|
||||||
* @return 返回字符串业务参数
|
* @return 返回字符串业务参数
|
||||||
*/
|
*/
|
||||||
String getBizContent();
|
String getBizContent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回业务对象
|
* 返回业务对象
|
||||||
|
*
|
||||||
* @return 业务对象
|
* @return 业务对象
|
||||||
*/
|
*/
|
||||||
T getBizObject();
|
T getBizObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回字符编码
|
* 返回字符编码
|
||||||
|
*
|
||||||
* @return 如UTF-8
|
* @return 如UTF-8
|
||||||
*/
|
*/
|
||||||
String getCharset();
|
String getCharset();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回接口名
|
* 返回接口名
|
||||||
|
*
|
||||||
* @return 如:alipay.goods.get
|
* @return 如:alipay.goods.get
|
||||||
*/
|
*/
|
||||||
String getMethod();
|
String getMethod();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回版本号
|
* 返回版本号
|
||||||
|
*
|
||||||
* @return 如:1.0
|
* @return 如:1.0
|
||||||
*/
|
*/
|
||||||
String getVersion();
|
String getVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回参数格式化
|
* 返回参数格式化
|
||||||
|
*
|
||||||
* @return 如:json
|
* @return 如:json
|
||||||
*/
|
*/
|
||||||
String getFormat();
|
String getFormat();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回签名类型
|
* 返回签名类型
|
||||||
|
*
|
||||||
* @return 如:RSA2
|
* @return 如:RSA2
|
||||||
*/
|
*/
|
||||||
String getSignType();
|
String getSignType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回时间戳
|
* 返回时间戳
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Date getTimestamp();
|
Date getTimestamp();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回token,即access_token
|
* 返回token,即access_token
|
||||||
|
*
|
||||||
* @return 返回token
|
* @return 返回token
|
||||||
*/
|
*/
|
||||||
String appAuthToken();
|
String appAuthToken();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回回调地址
|
* 返回回调地址
|
||||||
|
*
|
||||||
* @return 返回回调地址
|
* @return 返回回调地址
|
||||||
*/
|
*/
|
||||||
String getNotifyUrl();
|
String getNotifyUrl();
|
||||||
|
@@ -95,4 +95,16 @@ public class OpenContextImpl<T> implements OpenContext<T> {
|
|||||||
public String getNotifyUrl() {
|
public String getNotifyUrl() {
|
||||||
return rootJsonObject.getString(NOTIFY_URL_NAME);
|
return rootJsonObject.getString(NOTIFY_URL_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> E getBizObject(Class<E> clazz) {
|
||||||
|
if (bizObject != null && bizObject.getClass() == clazz) {
|
||||||
|
return (E) bizObject;
|
||||||
|
}
|
||||||
|
JSONObject bizJsonObj = this.rootJsonObject.getJSONObject(BIZ_CONTENT_NAME);
|
||||||
|
if (bizJsonObj == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return bizJsonObj.toJavaObject(clazz);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,9 +41,12 @@ public class AlipayController {
|
|||||||
// 接口名,使用默认版本号
|
// 接口名,使用默认版本号
|
||||||
@ApiMapping(value = "story.get")
|
@ApiMapping(value = "story.get")
|
||||||
public Story storyget() {
|
public Story storyget() {
|
||||||
|
// 获取开放平台参数
|
||||||
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
|
String appId = openContext.getAppId();
|
||||||
Story story = new Story();
|
Story story = new Story();
|
||||||
story.setId(1);
|
story.setId(1);
|
||||||
story.setName("海底小纵队(默认版本号)");
|
story.setName("海底小纵队(默认版本号), app_id:" + appId);
|
||||||
return story;
|
return story;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +70,39 @@ public class AlipayController {
|
|||||||
// 忽略验证
|
// 忽略验证
|
||||||
@ApiMapping(value = "story.get", version = "2.1", ignoreValidate = true)
|
@ApiMapping(value = "story.get", version = "2.1", ignoreValidate = true)
|
||||||
public Story getStory21(Story story) {
|
public Story getStory21(Story story) {
|
||||||
story.setName(story.getName() + ", story.get2.1, ignoreValidate = true");
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
|
// 此处的param和story参数是一样的
|
||||||
|
Story param = openContext.getBizObject(Story.class);
|
||||||
|
boolean isSame = story == param;
|
||||||
|
story.setName(story.getName() + ", story.get2.1, ignoreValidate = true, story==param:" + isSame);
|
||||||
return story;
|
return story;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 另一种方式,OpenContext泛型参数填bizObject类<br>
|
||||||
|
* 调用openContext.getBizObject()可直接获得对象<br>
|
||||||
|
* 此方式等价于:
|
||||||
|
* <pre>
|
||||||
|
* public Story getStory22(Story bizObject) {
|
||||||
|
* OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||||
|
* // 获取appid,更多方法查看OpenContext类
|
||||||
|
* String appId = openContext.getAppId();
|
||||||
|
* System.out.println(appId);
|
||||||
|
* return bizObject;
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
* @param openContext
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiMapping(value = "story.get", version = "2.2")
|
||||||
|
public Story getStory22(OpenContext<Story> openContext) {
|
||||||
|
Story bizObject = openContext.getBizObject();
|
||||||
|
// 获取appid,更多方法查看OpenContext类
|
||||||
|
String appId = openContext.getAppId();
|
||||||
|
System.out.println(appId);
|
||||||
|
return bizObject;
|
||||||
|
}
|
||||||
|
|
||||||
// http://localhost:2222/getStory2
|
// http://localhost:2222/getStory2
|
||||||
// 遗留接口具备开放平台能力
|
// 遗留接口具备开放平台能力
|
||||||
@ApiAbility
|
@ApiAbility
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.gitee.sop.test;
|
package com.gitee.sop.test;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.gitee.sop.test.alipay.AlipayApiException;
|
||||||
import com.gitee.sop.test.alipay.AlipaySignature;
|
import com.gitee.sop.test.alipay.AlipaySignature;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -178,4 +179,56 @@ public class AlipayClientPostTest extends TestBase {
|
|||||||
System.out.println(responseData);
|
System.out.println(responseData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 忽略验证,不校验签名,只需传接口名、版本号、业务参数
|
||||||
|
@Test
|
||||||
|
public void testIgnore() {
|
||||||
|
// 公共请求参数
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("method", "story.get");
|
||||||
|
params.put("version", "2.1");
|
||||||
|
// 业务参数
|
||||||
|
Map<String, String> bizContent = new HashMap<>();
|
||||||
|
bizContent.put("id", "222");
|
||||||
|
bizContent.put("name", "忽略验证name");
|
||||||
|
|
||||||
|
params.put("biz_content", JSON.toJSONString(bizContent));
|
||||||
|
|
||||||
|
System.out.println("----------- 返回结果 -----------");
|
||||||
|
String responseData = post(url, params);// 发送请求
|
||||||
|
System.out.println(responseData);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStoryget() throws AlipayApiException {
|
||||||
|
// 公共请求参数
|
||||||
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
|
params.put("app_id", appId);
|
||||||
|
params.put("method", "story.get");
|
||||||
|
params.put("version", "2.2");
|
||||||
|
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<>();
|
||||||
|
bizContent.put("id", "222");
|
||||||
|
bizContent.put("name", "忽略验证22");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user