mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
5.0
This commit is contained in:
@@ -44,6 +44,33 @@ const apiRouters = [
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
,
|
||||
{
|
||||
path: "/doc",
|
||||
meta: {
|
||||
title: "文档管理",
|
||||
icon: "ep:document",
|
||||
rank: 10
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/doc/setting",
|
||||
name: "DocSetting",
|
||||
meta: {
|
||||
title: "基础配置",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/doc/index",
|
||||
name: "DocList",
|
||||
meta: {
|
||||
title: "文档管理",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
// ,
|
||||
|
11
sop-admin/sop-admin-frontend/src/views/doc/index.vue
Normal file
11
sop-admin/sop-admin-frontend/src/views/doc/index.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
</style>
|
@@ -44,9 +44,9 @@ import {
|
||||
adaptive
|
||||
@paginationChange="handlePaginationChange"
|
||||
>
|
||||
<template #title>
|
||||
<!-- <template #title>
|
||||
<el-button type="primary" @click="handleAdd">新增接口</el-button>
|
||||
</template>
|
||||
</template>-->
|
||||
</PlusTable>
|
||||
<PlusDialogForm
|
||||
v-model:visible="dlgShow"
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.gitee.sop.payment;
|
||||
|
||||
|
||||
import cn.torna.swaggerplugin.SwaggerPlugin;
|
||||
|
||||
/**
|
||||
|
@@ -7,7 +7,6 @@ import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.dto.CommonFileData;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
import com.gitee.sop.support.dto.OpenRequest;
|
||||
import com.gitee.sop.support.exception.OpenException;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
@@ -18,7 +17,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
@@ -32,23 +30,6 @@ public class OpenStoryImpl implements OpenStory {
|
||||
|
||||
@Override
|
||||
public Integer save(StorySaveDTO storySaveDTO) {
|
||||
System.out.println("save storySaveDTO:" + storySaveDTO);
|
||||
System.out.println("appId:" + OpenContext.getAppId());
|
||||
System.out.println("apiName:" + OpenContext.getApiName());
|
||||
System.out.println("version:" + OpenContext.getVersion());
|
||||
System.out.println("token:" + OpenContext.getAppAuthToken());
|
||||
System.out.println("ip:" + OpenContext.getClientIp());
|
||||
System.out.println("traceId:" + OpenContext.getTraceId());
|
||||
System.out.println("locale:" + OpenContext.getLocale());
|
||||
System.out.println("notifyUrl:" + OpenContext.getNotifyUrl());
|
||||
|
||||
Assert.notNull(OpenContext.getAppId());
|
||||
Assert.notNull(OpenContext.getApiName());
|
||||
Assert.notNull(OpenContext.getVersion());
|
||||
Assert.notNull(OpenContext.getClientIp());
|
||||
Assert.notNull(OpenContext.getTraceId());
|
||||
Assert.notNull(OpenContext.getLocale());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -91,30 +72,26 @@ public class OpenStoryImpl implements OpenStory {
|
||||
|
||||
// 演示获取上下文
|
||||
@Override
|
||||
public StoryResponse getByIdV3(Long id, OpenRequest request) {
|
||||
public StoryResponse getContext(Long id, OpenContext context) {
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(3);
|
||||
storyResponse.setName(request.toString());
|
||||
|
||||
String notifyUrl = request.getNotifyUrl();
|
||||
storyResponse.setName(context.toString());
|
||||
// 获取回调参数
|
||||
String notifyUrl = context.getNotifyUrl();
|
||||
System.out.println(notifyUrl);
|
||||
// 方式2
|
||||
String notifyUrl2 = OpenContext.getNotifyUrl();
|
||||
System.out.println(notifyUrl2);
|
||||
|
||||
System.out.println(Objects.equals(notifyUrl2, notifyUrl));
|
||||
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoryResponse upload(StorySaveDTO storySaveDTO, FileData file) {
|
||||
System.out.println("upload:" + storySaveDTO);
|
||||
System.out.println("getName:" + file.getName());
|
||||
System.out.println("getOriginalFilename:" + file.getOriginalFilename());
|
||||
checkFile(Arrays.asList(file));
|
||||
|
||||
StoryResponse storyResponse = new StoryResponse();
|
||||
storyResponse.setId(1);
|
||||
storyResponse.setName(storySaveDTO.getStoryName());
|
||||
storyResponse.setName(file.getOriginalFilename());
|
||||
return storyResponse;
|
||||
}
|
||||
|
||||
|
@@ -3,8 +3,8 @@ package com.gitee.sop.storyweb.open;
|
||||
import com.gitee.sop.storyweb.open.req.StorySaveDTO;
|
||||
import com.gitee.sop.storyweb.open.resp.StoryResponse;
|
||||
import com.gitee.sop.support.annotation.Open;
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
import com.gitee.sop.support.dto.OpenRequest;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
@@ -33,8 +33,8 @@ public interface OpenStory {
|
||||
@Open(value = "story.get", version = "2.0")
|
||||
StoryResponse getByIdV2(Long id);
|
||||
|
||||
@Open(value = "story.get", version = "3.0")
|
||||
StoryResponse getByIdV3(Long id, OpenRequest request);
|
||||
@Open(value = "story.get.context")
|
||||
StoryResponse getContext(Long id, OpenContext context);
|
||||
|
||||
|
||||
// 默认方法,注解放在这里也有效
|
||||
@@ -52,13 +52,19 @@ public interface OpenStory {
|
||||
|
||||
// 演示多文件上传
|
||||
@Open("story.upload.more")
|
||||
StoryResponse upload2(StorySaveDTO storySaveDTO,
|
||||
@NotNull(message = "身份证正面必填") FileData idCardFront,
|
||||
@NotNull(message = "身份证背面必填") FileData idCardBack);
|
||||
StoryResponse upload2(
|
||||
StorySaveDTO storySaveDTO,
|
||||
@NotNull(message = "身份证正面必填") FileData idCardFront,
|
||||
@NotNull(message = "身份证背面必填") FileData idCardBack
|
||||
);
|
||||
|
||||
// 演示多文件上传
|
||||
@Open("story.upload.list")
|
||||
StoryResponse upload3(StorySaveDTO storySaveDTO, @Size(min = 2, message = "最少上传2个文件") List<FileData> files);
|
||||
StoryResponse upload3(
|
||||
StorySaveDTO storySaveDTO,
|
||||
@Size(min = 2, message = "最少上传2个文件")
|
||||
List<FileData> files
|
||||
);
|
||||
|
||||
// 下载
|
||||
@Open("story.download")
|
||||
|
@@ -18,11 +18,10 @@ import com.gitee.sop.gateway.service.RouteService;
|
||||
import com.gitee.sop.gateway.service.interceptor.RouteInterceptor;
|
||||
import com.gitee.sop.gateway.service.validate.Validator;
|
||||
import com.gitee.sop.gateway.util.ClassUtil;
|
||||
import com.gitee.sop.support.constants.AttachmentNames;
|
||||
import com.gitee.sop.support.dto.CommonFileData;
|
||||
import com.gitee.sop.support.dto.DefaultOpenRequest;
|
||||
import com.gitee.sop.support.context.DefaultOpenContext;
|
||||
import com.gitee.sop.support.dto.FileData;
|
||||
import com.gitee.sop.support.dto.OpenRequest;
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -33,8 +32,6 @@ import java.util.Optional;
|
||||
import javax.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.common.utils.ClassUtils;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcContextAttachment;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -84,7 +81,6 @@ public class RouteServiceImpl implements RouteService {
|
||||
}
|
||||
|
||||
protected Object doRoute(ApiRequestContext apiRequestContext, ApiInfoDTO apiInfo) {
|
||||
setAttachment(apiRequestContext);
|
||||
String paramInfo = apiInfo.getParamInfo();
|
||||
List<ParamInfoDTO> paramInfoList = JSON.parseArray(paramInfo, ParamInfoDTO.class);
|
||||
return genericServiceInvoker.invoke(
|
||||
@@ -95,19 +91,6 @@ public class RouteServiceImpl implements RouteService {
|
||||
);
|
||||
}
|
||||
|
||||
protected void setAttachment(ApiRequestContext apiRequestContext) {
|
||||
ApiRequest apiRequest = apiRequestContext.getApiRequest();
|
||||
RpcContextAttachment clientAttachment = RpcContext.getClientAttachment();
|
||||
clientAttachment.setAttachment(AttachmentNames.APP_ID, apiRequest.getAppId());
|
||||
clientAttachment.setAttachment(AttachmentNames.API_NAME, apiRequest.getMethod());
|
||||
clientAttachment.setAttachment(AttachmentNames.VERSION, apiRequest.getVersion());
|
||||
clientAttachment.setAttachment(AttachmentNames.APP_AUTH_TOKEN, apiRequest.getAppAuthToken());
|
||||
clientAttachment.setAttachment(AttachmentNames.NOTIFY_URL, apiRequest.getNotifyUrl());
|
||||
clientAttachment.setAttachment(AttachmentNames.CLIENT_IP, apiRequestContext.getIp());
|
||||
clientAttachment.setAttachment(AttachmentNames.TRACE_ID, apiRequestContext.getTraceId());
|
||||
clientAttachment.setAttachment(AttachmentNames.LOCALE, apiRequestContext.getLocale().toLanguageTag());
|
||||
}
|
||||
|
||||
protected void doPreRoute(ApiRequestContext apiRequestContext, ApiInfoDTO apiInfoDTO) {
|
||||
for (RouteInterceptor routeInterceptor : routeInterceptors) {
|
||||
routeInterceptor.preRoute(apiRequestContext, apiInfoDTO);
|
||||
@@ -144,8 +127,8 @@ public class RouteServiceImpl implements RouteService {
|
||||
String actualType = paramInfoDTO.getActualType();
|
||||
|
||||
// 上下文
|
||||
if (Objects.equals(type, OpenRequest.class.getName())) {
|
||||
OpenRequest openRequest = buildOpenRequest(apiRequestContext);
|
||||
if (Objects.equals(type, OpenContext.class.getName())) {
|
||||
OpenContext openRequest = buildOpenContext(apiRequestContext);
|
||||
params.add(openRequest);
|
||||
} else if (Objects.equals(type, FileData.class.getName()) || Objects.equals(actualType, FileData.class.getName())) {
|
||||
// 处理文件上传
|
||||
@@ -174,9 +157,9 @@ public class RouteServiceImpl implements RouteService {
|
||||
return params.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
protected OpenRequest buildOpenRequest(ApiRequestContext apiRequestContext) {
|
||||
protected OpenContext buildOpenContext(ApiRequestContext apiRequestContext) {
|
||||
ApiRequest apiRequest = apiRequestContext.getApiRequest();
|
||||
DefaultOpenRequest defaultOpenRequest = new DefaultOpenRequest();
|
||||
DefaultOpenContext defaultOpenRequest = new DefaultOpenContext();
|
||||
defaultOpenRequest.setAppId(apiRequest.getAppId());
|
||||
defaultOpenRequest.setApiName(apiRequest.getMethod());
|
||||
defaultOpenRequest.setVersion(apiRequest.getVersion());
|
||||
|
@@ -25,7 +25,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.16</version>
|
||||
<version>2.0.52</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -44,7 +44,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<version>1.18.34</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -102,5 +102,12 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven_central</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
@@ -6,12 +6,11 @@ import com.alibaba.fastjson.parser.Feature;
|
||||
import com.gitee.sop.sdk.common.DataNameBuilder;
|
||||
import com.gitee.sop.sdk.common.OpenConfig;
|
||||
import com.gitee.sop.sdk.common.RequestForm;
|
||||
import com.gitee.sop.sdk.common.Result;
|
||||
import com.gitee.sop.sdk.common.SopSdkConstants;
|
||||
import com.gitee.sop.sdk.common.SopSdkErrors;
|
||||
import com.gitee.sop.sdk.exception.SdkException;
|
||||
import com.gitee.sop.sdk.request.BaseRequest;
|
||||
import com.gitee.sop.sdk.response.BaseResponse;
|
||||
import com.gitee.sop.sdk.response.ErrorResponse;
|
||||
import com.gitee.sop.sdk.sign.SopSignException;
|
||||
import com.gitee.sop.sdk.sign.SopSignature;
|
||||
import com.gitee.sop.sdk.sign.StringUtils;
|
||||
@@ -135,7 +134,7 @@ public class OpenClient {
|
||||
* @param <T> 返回对应的Response
|
||||
* @return 返回Response
|
||||
*/
|
||||
public <T extends BaseResponse> T execute(BaseRequest<T> request) {
|
||||
public <T> Result<T> execute(BaseRequest<T> request) {
|
||||
return this.execute(request, null);
|
||||
}
|
||||
|
||||
@@ -147,7 +146,7 @@ public class OpenClient {
|
||||
* @param <T> 返回对应的Response
|
||||
* @return 返回Response
|
||||
*/
|
||||
public <T extends BaseResponse> T execute(BaseRequest<T> request, String accessToken) {
|
||||
public <T> Result<T> execute(BaseRequest<T> request, String accessToken) {
|
||||
RequestForm requestForm = request.createRequestForm(this.openConfig);
|
||||
// 表单数据
|
||||
Map<String, String> form = requestForm.getForm();
|
||||
@@ -191,28 +190,25 @@ public class OpenClient {
|
||||
* @param <T> 返回结果
|
||||
* @return 返回对于的Response对象
|
||||
*/
|
||||
protected <T extends BaseResponse> T parseResponse(String resp, BaseRequest<T> request) {
|
||||
protected <T> Result<T> parseResponse(String resp, BaseRequest<T> request) {
|
||||
String method = request.getMethod();
|
||||
String rootNodeName = dataNameBuilder.build(method);
|
||||
JSONObject jsonObject = JSON.parseObject(resp, Feature.OrderedField);
|
||||
String errorResponseName = this.openConfig.getErrorResponseName();
|
||||
boolean errorResponse = jsonObject.containsKey(errorResponseName);
|
||||
if (errorResponse) {
|
||||
rootNodeName = errorResponseName;
|
||||
}
|
||||
JSONObject data = jsonObject.getJSONObject(rootNodeName);
|
||||
String sign = jsonObject.getString(openConfig.getSignName());
|
||||
// 是否要验证返回的sign
|
||||
if (StringUtils.areNotEmpty(sign, publicKeyPlatform)) {
|
||||
String signContent = buildBizJson(rootNodeName, resp);
|
||||
if (!this.checkResponseSign(signContent, sign, publicKeyPlatform)) {
|
||||
ErrorResponse error = SopSdkErrors.CHECK_RESPONSE_SIGN_ERROR.getErrorResponse();
|
||||
data = JSON.parseObject(JSON.toJSONString(error));
|
||||
return SopSdkErrors.CHECK_RESPONSE_SIGN_ERROR.getErrorResult();
|
||||
}
|
||||
}
|
||||
T t = data.toJavaObject(request.getResponseClass());
|
||||
t.setBody(jsonObject.getString(rootNodeName));
|
||||
return t;
|
||||
Result result = jsonObject.toJavaObject(Result.class);
|
||||
if (data != null) {
|
||||
T dataObj = data.toJavaObject(request.getResponseClass());
|
||||
result.setData(dataObj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.gitee.sop.sdk.common.OpenConfig;
|
||||
import com.gitee.sop.sdk.common.RequestForm;
|
||||
import com.gitee.sop.sdk.common.RequestMethod;
|
||||
import com.gitee.sop.sdk.common.Result;
|
||||
import com.gitee.sop.sdk.common.SopSdkErrors;
|
||||
import com.gitee.sop.sdk.common.UploadFile;
|
||||
import com.gitee.sop.sdk.response.ErrorResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -68,7 +68,7 @@ public class OpenRequest {
|
||||
}
|
||||
|
||||
protected String causeException(Exception e) {
|
||||
ErrorResponse result = SopSdkErrors.HTTP_ERROR.getErrorResponse();
|
||||
Result result = SopSdkErrors.HTTP_ERROR.getErrorResult();
|
||||
return JSON.toJSONString(result);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ package com.gitee.sop.sdk.common;
|
||||
* @author 六如
|
||||
*/
|
||||
public class CustomDataNameBuilder implements DataNameBuilder {
|
||||
private String dataName = "result";
|
||||
private String dataName = "data";
|
||||
|
||||
public CustomDataNameBuilder() {
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class OpenConfig {
|
||||
public static DataNameBuilder DATA_NAME_BUILDER = new DefaultDataNameBuilder();
|
||||
public static DataNameBuilder DATA_NAME_BUILDER = new CustomDataNameBuilder();
|
||||
|
||||
/** 成功返回码值 */
|
||||
private String successCode = "10000";
|
||||
private String successCode = "0";
|
||||
/** 默认版本号 */
|
||||
private String defaultVersion = "1.0";
|
||||
/** 字符编码 */
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package com.gitee.sop.sdk.common;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.gitee.sop.sdk.sign.StringUtils;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class Result<T> {
|
||||
private String code;
|
||||
private String msg;
|
||||
private String subCode;
|
||||
private String subMsg;
|
||||
private T data;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public boolean isSuccess() {
|
||||
return StringUtils.isEmpty(subCode);
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,5 @@
|
||||
package com.gitee.sop.sdk.common;
|
||||
|
||||
import com.gitee.sop.sdk.response.ErrorResponse;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@@ -23,13 +21,13 @@ public enum SopSdkErrors {
|
||||
this.subMsg = msg;
|
||||
}
|
||||
|
||||
public ErrorResponse getErrorResponse() {
|
||||
ErrorResponse errorResponse = new ErrorResponse();
|
||||
errorResponse.setCode(code);
|
||||
errorResponse.setSubCode(subCode);
|
||||
errorResponse.setSubMsg(subMsg);
|
||||
errorResponse.setMsg(msg);
|
||||
return errorResponse;
|
||||
public Result getErrorResult() {
|
||||
Result result = new Result();
|
||||
result.setCode(code);
|
||||
result.setSubCode(subCode);
|
||||
result.setSubMsg(subMsg);
|
||||
result.setMsg(msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String code;
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package com.gitee.sop.sdk.model;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GetStoryModel {
|
||||
|
||||
@JSONField(name = "name")
|
||||
private String name;
|
||||
private Integer id;
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@ import com.gitee.sop.sdk.common.OpenConfig;
|
||||
import com.gitee.sop.sdk.common.RequestForm;
|
||||
import com.gitee.sop.sdk.common.RequestMethod;
|
||||
import com.gitee.sop.sdk.common.UploadFile;
|
||||
import com.gitee.sop.sdk.response.BaseResponse;
|
||||
import com.gitee.sop.sdk.util.ClassUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -34,7 +33,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
public abstract class BaseRequest<T extends BaseResponse> {
|
||||
public abstract class BaseRequest<T> {
|
||||
|
||||
private static final String EMPTY_JSON = "{}";
|
||||
|
||||
|
@@ -1,22 +0,0 @@
|
||||
package com.gitee.sop.sdk.request;
|
||||
|
||||
import com.gitee.sop.sdk.response.CommonResponse;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class CommonRequest extends BaseRequest<CommonResponse> {
|
||||
|
||||
public CommonRequest(String method) {
|
||||
super(method, null);
|
||||
}
|
||||
|
||||
public CommonRequest(String method, String version) {
|
||||
super(method, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String method() {
|
||||
return "";
|
||||
}
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package com.gitee.sop.sdk.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.gitee.sop.sdk.sign.StringUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 返回对象,后续返回对象都要继承这个类
|
||||
* {
|
||||
* "alipay_trade_close_response": {
|
||||
* "code": "20000",
|
||||
* "msg": "Service Currently Unavailable",
|
||||
* "sub_code": "isp.unknown-error",
|
||||
* "sub_msg": "系统繁忙"
|
||||
* },
|
||||
* "sign": "ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE"
|
||||
* }
|
||||
* @author 六如
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
public abstract class BaseResponse {
|
||||
|
||||
@JSONField(name = "request_id")
|
||||
private String requestId;
|
||||
private String code;
|
||||
private String msg;
|
||||
@JSONField(name = "sub_code")
|
||||
private String subCode;
|
||||
@JSONField(name = "sub_msg")
|
||||
private String subMsg;
|
||||
@JSONField(serialize = false)
|
||||
private String body;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public boolean isSuccess() {
|
||||
return StringUtils.isEmpty(subCode);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,8 +0,0 @@
|
||||
package com.gitee.sop.sdk.response;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class CommonResponse extends BaseResponse {
|
||||
|
||||
}
|
@@ -11,9 +11,9 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class DemoFileUploadResponse extends BaseResponse {
|
||||
public class DemoFileUploadResponse {
|
||||
|
||||
private List<FileMeta> files = new ArrayList();
|
||||
private List<FileMeta> files = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
public static class FileMeta {
|
||||
|
@@ -1,7 +0,0 @@
|
||||
package com.gitee.sop.sdk.response;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class ErrorResponse extends BaseResponse {
|
||||
}
|
@@ -1,14 +1,12 @@
|
||||
package com.gitee.sop.sdk.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class GetStoryResponse extends BaseResponse {
|
||||
public class GetStoryResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private Date gmt_create;
|
||||
private Date addTime;
|
||||
}
|
||||
|
@@ -1,14 +1,12 @@
|
||||
package com.gitee.sop.sdk.response;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class OpenAuthTokenAppResponse extends BaseResponse {
|
||||
public class OpenAuthTokenAppResponse {
|
||||
/**
|
||||
* 授权令牌
|
||||
*/
|
||||
|
@@ -28,7 +28,7 @@ public abstract class StringUtils {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if ((Character.isWhitespace(value.charAt(i)) == false)) {
|
||||
if ((!Character.isWhitespace(value.charAt(i)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,13 @@
|
||||
package com.gitee.sop.sdk;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.gitee.sop.sdk.client.OpenClient;
|
||||
import com.gitee.sop.sdk.common.RequestMethod;
|
||||
import com.gitee.sop.sdk.common.Result;
|
||||
import com.gitee.sop.sdk.common.UploadFile;
|
||||
import com.gitee.sop.sdk.model.DemoFileUploadModel;
|
||||
import com.gitee.sop.sdk.model.GetStoryModel;
|
||||
import com.gitee.sop.sdk.request.CommonRequest;
|
||||
import com.gitee.sop.sdk.request.DemoFileUploadRequest;
|
||||
import com.gitee.sop.sdk.request.GetStoryRequest;
|
||||
import com.gitee.sop.sdk.response.CommonResponse;
|
||||
import com.gitee.sop.sdk.response.DemoFileUploadResponse;
|
||||
import com.gitee.sop.sdk.response.GetStoryResponse;
|
||||
import junit.framework.TestCase;
|
||||
@@ -18,69 +15,47 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SdkTest extends TestCase {
|
||||
String url = "http://localhost:8081/api";
|
||||
String appId = "2019032617262200001";
|
||||
/** 开发者私钥 */
|
||||
/**
|
||||
* 开发者私钥
|
||||
*/
|
||||
String privateKeyIsv = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4EB1b8x8QJ7Ua4GcIUqeUxGHdQpzNbJdaQvoi06lgccmL+PHzminkFYON7alj1CjDN833j7QMHdPtS9l7B67fOU/p2LAAkPMtoVBfxQt9aFj7B8rEhGCz02iJIBAgMBAAECggEARqOuIpY0v6WtJBfmR3lGIOOokLrhfJrGTLF8CiZMQha+SRJ7/wOLPlsH9SbjPlopyViTXCuYwbzn2tdABigkBHYXxpDV6CJZjzmRZ+FY3S/0POlTFElGojYUJ3CooWiVfyUMhdg5vSuOq0oCny53woFrf32zPHYGiKdvU5Djku1onbDU0Lw8w+5tguuEZ76kZ/lUcccGy5978FFmYpzY/65RHCpvLiLqYyWTtaNT1aQ/9pw4jX9HO9NfdJ9gYFK8r/2f36ZE4hxluAfeOXQfRC/WhPmiw/ReUhxPznG/WgKaa/OaRtAx3inbQ+JuCND7uuKeRe4osP2jLPHPP6AUwQKBgQDUNu3BkLoKaimjGOjCTAwtp71g1oo+k5/uEInAo7lyEwpV0EuUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ=";
|
||||
/** 开放平台提供的公钥
|
||||
* 前往SOP-ADMIN,ISV管理--秘钥管理,生成平台提供的公私钥,然后把【平台公钥】放到这里 */
|
||||
/**
|
||||
* 开放平台提供的公钥
|
||||
* 前往SOP-ADMIN,ISV管理--秘钥管理,生成平台提供的公私钥,然后把【平台公钥】放到这里
|
||||
*/
|
||||
String publicKeyPlatform = "";
|
||||
|
||||
// 声明一个就行
|
||||
OpenClient client = new OpenClient(url, appId, privateKeyIsv, publicKeyPlatform);
|
||||
|
||||
// 标准用法
|
||||
@Test
|
||||
public void testGet() {
|
||||
// 创建请求对象
|
||||
GetStoryRequest request = new GetStoryRequest();
|
||||
// 请求参数
|
||||
GetStoryModel model = new GetStoryModel();
|
||||
model.setName("白雪公主");
|
||||
model.setId(1);
|
||||
request.setBizModel(model);
|
||||
|
||||
// 发送请求
|
||||
GetStoryResponse response = client.execute(request);
|
||||
Result<GetStoryResponse> result = client.execute(request);
|
||||
|
||||
if (response.isSuccess()) {
|
||||
if (result.isSuccess()) {
|
||||
GetStoryResponse response = result.getData();
|
||||
// 返回结果
|
||||
System.out.println(String.format("response:%s",
|
||||
JSON.toJSONString(response)));
|
||||
} else {
|
||||
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
|
||||
System.out.println("错误,subCode:" + result.getSubCode() + ", subMsg:" + result.getSubMsg());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 懒人版,如果不想添加Request,Response,可以用这种方式,返回全部是String,后续自己处理json
|
||||
@Test
|
||||
public void testLazy() {
|
||||
// 创建请求对象
|
||||
CommonRequest request = new CommonRequest("story.get");
|
||||
// 请求参数
|
||||
Map<String, Object> bizModel = new HashMap<>();
|
||||
bizModel.put("name", "白雪公主");
|
||||
request.setBizModel(bizModel);
|
||||
// request.setRequestMethod(RequestMethod.GET);
|
||||
|
||||
// 发送请求
|
||||
CommonResponse response = client.execute(request);
|
||||
|
||||
if (response.isSuccess()) {
|
||||
// 返回结果
|
||||
String body = response.getBody();
|
||||
JSONObject jsonObject = JSON.parseObject(body);
|
||||
System.out.println(jsonObject);
|
||||
} else {
|
||||
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
|
||||
}
|
||||
}
|
||||
|
||||
// 文件上传
|
||||
@Test
|
||||
public void testUpload() throws IOException {
|
||||
@@ -96,15 +71,16 @@ public class SdkTest extends TestCase {
|
||||
request.addFile(new UploadFile("file1", new File(root + "/src/main/resources/file1.txt")));
|
||||
request.addFile(new UploadFile("file2", new File(root + "/src/main/resources/file2.txt")));
|
||||
|
||||
DemoFileUploadResponse response = client.execute(request);
|
||||
Result<DemoFileUploadResponse> result = client.execute(request);
|
||||
|
||||
System.out.println("--------------------");
|
||||
if (response.isSuccess()) {
|
||||
if (result.isSuccess()) {
|
||||
DemoFileUploadResponse response = result.getData();
|
||||
List<DemoFileUploadResponse.FileMeta> responseFiles = response.getFiles();
|
||||
System.out.println("您上传的文件信息:");
|
||||
responseFiles.forEach(System.out::println);
|
||||
} else {
|
||||
System.out.println(JSON.toJSONString(response));
|
||||
System.out.println(JSON.toJSONString(result));
|
||||
}
|
||||
System.out.println("--------------------");
|
||||
}
|
||||
|
@@ -17,10 +17,10 @@ import java.nio.charset.StandardCharsets;
|
||||
public class SwaggerPlugin {
|
||||
|
||||
/**
|
||||
* 推送文档,前提:把<code>doc-plugin.json</code>文件复制到resources下
|
||||
* 推送文档,前提:把<code>doc.json</code>文件复制到resources下
|
||||
*/
|
||||
public static void pushDoc() {
|
||||
pushDoc("doc-plugin.json");
|
||||
pushDoc("doc.json");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -58,7 +58,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -352,12 +351,12 @@ public class SwaggerPluginService {
|
||||
if (apiOperation.hidden()) {
|
||||
throw new HiddenException("Hidden API(@ApiOperation.hidden=true):" + apiOperation.value());
|
||||
}
|
||||
if (existsApiIgnore) {
|
||||
ApiIgnore apiIgnore = method.getAnnotation(ApiIgnore.class);
|
||||
if (apiIgnore != null) {
|
||||
throw new IgnoreException("Ignore API(@ApiIgnore):" + apiOperation.value());
|
||||
}
|
||||
}
|
||||
// if (existsApiIgnore) {
|
||||
// ApiIgnore apiIgnore = method.getAnnotation(ApiIgnore.class);
|
||||
// if (apiIgnore != null) {
|
||||
// throw new IgnoreException("Ignore API(@ApiIgnore):" + apiOperation.value());
|
||||
// }
|
||||
// }
|
||||
return doBuildDocItem(requestInfoBuilder);
|
||||
}
|
||||
|
||||
@@ -918,12 +917,12 @@ public class SwaggerPluginService {
|
||||
if (api != null && api.hidden()) {
|
||||
throw new HiddenException("Hidden doc(@Api.hidden=true):" + api.value());
|
||||
}
|
||||
if (existsApiIgnore) {
|
||||
ApiIgnore apiIgnore = AnnotationUtils.findAnnotation(controllerClass, ApiIgnore.class);
|
||||
if (apiIgnore != null) {
|
||||
throw new IgnoreException("Ignore doc(@ApiIgnore):" + controllerClass.getName());
|
||||
}
|
||||
}
|
||||
// if (existsApiIgnore) {
|
||||
// ApiIgnore apiIgnore = AnnotationUtils.findAnnotation(controllerClass, ApiIgnore.class);
|
||||
// if (apiIgnore != null) {
|
||||
// throw new IgnoreException("Ignore doc(@ApiIgnore):" + controllerClass.getName());
|
||||
// }
|
||||
// }
|
||||
String name, description;
|
||||
int position = 0;
|
||||
if (api == null) {
|
||||
|
@@ -1,43 +0,0 @@
|
||||
package com.gitee.sop.support.constants;
|
||||
|
||||
/**
|
||||
* RPC附件name
|
||||
*
|
||||
* @author 六如
|
||||
*/
|
||||
public class AttachmentNames {
|
||||
|
||||
/**
|
||||
* 分配给开发者的应用ID
|
||||
*/
|
||||
public static final String APP_ID = "client.app_id";
|
||||
/**
|
||||
* 接口名称
|
||||
*/
|
||||
public static final String API_NAME = "client.method";
|
||||
/**
|
||||
* 调用的接口版本
|
||||
*/
|
||||
public static final String VERSION = "client.version";
|
||||
/**
|
||||
* 开放平台主动通知商户服务器里指定的页面http/https路径
|
||||
*/
|
||||
public static final String NOTIFY_URL = "client.notify_url";
|
||||
/**
|
||||
* OAuth 2.0授权token
|
||||
*/
|
||||
public static final String APP_AUTH_TOKEN = "client.app_auth_token";
|
||||
/**
|
||||
* 请求id
|
||||
*/
|
||||
public static final String CLIENT_IP = "client.ip";
|
||||
/**
|
||||
* 请求traceId
|
||||
*/
|
||||
public static final String TRACE_ID = "client.trace_id";
|
||||
/**
|
||||
* 请求locale
|
||||
*/
|
||||
public static final String LOCALE = "client.locale";
|
||||
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.support.dto;
|
||||
package com.gitee.sop.support.context;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Locale;
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class DefaultOpenRequest implements OpenRequest, Serializable {
|
||||
public class DefaultOpenContext implements OpenContext, Serializable {
|
||||
private static final long serialVersionUID = -3218354527911979685L;
|
||||
|
||||
/**
|
@@ -1,77 +1,50 @@
|
||||
package com.gitee.sop.support.context;
|
||||
|
||||
import com.gitee.sop.support.constants.AttachmentNames;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class OpenContext {
|
||||
|
||||
public interface OpenContext {
|
||||
|
||||
/**
|
||||
* 获取appId
|
||||
*/
|
||||
public static String getAppId() {
|
||||
return getAttachment(AttachmentNames.APP_ID);
|
||||
}
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* 获取apiName
|
||||
*/
|
||||
public static String getApiName() {
|
||||
return getAttachment(AttachmentNames.API_NAME);
|
||||
}
|
||||
String getApiName();
|
||||
|
||||
/**
|
||||
* 获取version
|
||||
*/
|
||||
public static String getVersion() {
|
||||
return getAttachment(AttachmentNames.VERSION);
|
||||
}
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* 获取token,没有返回null
|
||||
*/
|
||||
public static String getAppAuthToken() {
|
||||
return getAttachment(AttachmentNames.APP_AUTH_TOKEN);
|
||||
}
|
||||
String getAppAuthToken();
|
||||
|
||||
/**
|
||||
* 获取客户端ip
|
||||
*/
|
||||
public static String getClientIp() {
|
||||
return getAttachment(AttachmentNames.CLIENT_IP);
|
||||
}
|
||||
String getClientIp();
|
||||
|
||||
/**
|
||||
* 获取回调地址
|
||||
*/
|
||||
public static String getNotifyUrl() {
|
||||
return getAttachment(AttachmentNames.NOTIFY_URL);
|
||||
}
|
||||
String getNotifyUrl();
|
||||
|
||||
/**
|
||||
* 获取唯一请求id
|
||||
*/
|
||||
public static String getTraceId() {
|
||||
return getAttachment(AttachmentNames.TRACE_ID);
|
||||
}
|
||||
String getTraceId();
|
||||
|
||||
/**
|
||||
* 获取locale
|
||||
*/
|
||||
public static Locale getLocale() {
|
||||
String langTag = getAttachment(AttachmentNames.LOCALE);
|
||||
if (langTag == null) {
|
||||
return Locale.SIMPLIFIED_CHINESE;
|
||||
}
|
||||
return Locale.forLanguageTag(langTag);
|
||||
}
|
||||
Locale getLocale();
|
||||
|
||||
private static String getAttachment(String key) {
|
||||
return RpcContext.getServerAttachment().getAttachment(key);
|
||||
}
|
||||
}
|
||||
|
@@ -1,50 +0,0 @@
|
||||
package com.gitee.sop.support.dto;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public interface OpenRequest {
|
||||
|
||||
/**
|
||||
* 获取appId
|
||||
*/
|
||||
String getAppId();
|
||||
|
||||
/**
|
||||
* 获取apiName
|
||||
*/
|
||||
String getApiName();
|
||||
|
||||
/**
|
||||
* 获取version
|
||||
*/
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* 获取token,没有返回null
|
||||
*/
|
||||
String getAppAuthToken();
|
||||
|
||||
/**
|
||||
* 获取客户端ip
|
||||
*/
|
||||
String getClientIp();
|
||||
|
||||
/**
|
||||
* 获取回调地址
|
||||
*/
|
||||
String getNotifyUrl();
|
||||
|
||||
/**
|
||||
* 获取唯一请求id
|
||||
*/
|
||||
String getTraceId();
|
||||
|
||||
/**
|
||||
* 获取locale
|
||||
*/
|
||||
Locale getLocale();
|
||||
|
||||
}
|
@@ -1,6 +1,5 @@
|
||||
package com.gitee.sop.support.exception;
|
||||
|
||||
import com.gitee.sop.support.context.OpenContext;
|
||||
import com.gitee.sop.support.message.I18nMessage;
|
||||
import com.gitee.sop.support.message.OpenMessage;
|
||||
import com.gitee.sop.support.message.OpenMessageFactory;
|
||||
@@ -29,7 +28,7 @@ public class OpenException extends RuntimeException {
|
||||
}
|
||||
|
||||
public OpenException(I18nMessage openError, Object... params) {
|
||||
this(openError, OpenContext.getLocale(), params);
|
||||
this(openError, Locale.SIMPLIFIED_CHINESE, params);
|
||||
}
|
||||
|
||||
public OpenException(String subCode, String subMsg, String solution) {
|
||||
|
@@ -1,2 +1,2 @@
|
||||
com.gitee.sop.support.dto.CommonFileData
|
||||
com.gitee.sop.support.dto.DefaultOpenRequest
|
||||
com.gitee.sop.support.context.DefaultOpenContext
|
||||
|
@@ -29,7 +29,6 @@
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-doc-plugin</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- dubbo依赖 -->
|
||||
<dependency>
|
||||
|
@@ -114,12 +114,12 @@ public class AllInOneTest extends TestBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 多版本2.0
|
||||
* 获取上下文信息
|
||||
*/
|
||||
public void testGet_v3() {
|
||||
public void testGetContext() {
|
||||
Client.RequestBuilder requestBuilder = new Client.RequestBuilder()
|
||||
.method("story.get")
|
||||
.version("3.0")
|
||||
.method("story.get.context")
|
||||
.version("1.0")
|
||||
.notifyUrl("http://www.baidu.com")
|
||||
.bizContent(new BizContent().add("id", "2").add("name", "葫芦娃2"))
|
||||
.httpMethod(HttpTool.HTTPMethod.GET)
|
||||
|
Reference in New Issue
Block a user