Commit 93162abe authored by zhangc's avatar zhangc

添加api测试接口

parent edbf048a
......@@ -9,6 +9,7 @@ CREATE TABLE `t_api_interface` (
`api_path` varchar(100) DEFAULT NULL COMMENT '请求地址',
`target_url` varchar(100) DEFAULT NULL COMMENT '目标url',
`api_type` varchar(50) NULL DEFAULT '' COMMENT 'api类型:1 数据银行制作大数据表 2 数据银行制作数据包,3,数据银行制作自定义API 4 API实时接入 6 标签查询 9自定义',
`req_method` varchar(20) NULL DEFAULT NULL COMMENT '请求方式: GET, POST',
`api_function` varchar(200) DEFAULT NULL COMMENT '接口功能',
`join_type` varchar(50) NULL DEFAULT NULL COMMENT '接入类型:字典表对应key值',
`test_example` varchar(255) NULL DEFAULT NULL COMMENT '测试实例',
......@@ -49,6 +50,8 @@ CREATE TABLE `t_api_interface_custom` (
`resp_code` varchar(300) DEFAULT NULL COMMENT '响应状态码',
`api_example` varchar(300) DEFAULT NULL COMMENT 'api返回样例',
`inbox_param` varchar(300) NULL DEFAULT NULL COMMENT '固定参数',
`page_num` int(10) NULL DEFAULT '1' COMMENT '当前页',
`page_size` int(10) NULL DEFAULT '100' COMMENT '当前页显示数'
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`create_user` varchar(100) DEFAULT NULL COMMENT '创建人',
......
......@@ -37,7 +37,6 @@ public enum GatewayResultCode implements ResultCode {
ILLEGAL_TIMETEMP("ILLEGAL_TIMETEMP", "无效时间戳"),
/** 请求次数受限 */
REQUEST_LIMIT_EXCEPTION("REQUEST_LIMIT_EXCEPTION", "请求次数受限"),
......@@ -60,6 +59,12 @@ public enum GatewayResultCode implements ResultCode {
/** API状态异常 */
API_STATUS_EXCEPTION("API_STATUS_EXCEPTION", "API状态异常"),
/** API类型错误 */
API_TYPE_ERROR("API_TYPE_ERROR", "API类型错误"),
/** 文件地址不存在 */
DATA_BIG_ADDR_UNEXIST("DATA_BIG_ADDR_UNEXIST", "文件地址不存在!"),
/** 请求组织状态异常 */
ORG_STATE_EXCEPTION("ORG_STATE_EXCEPTION", "请求组织状态异常"),
/** 请求信息不存在 */
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jz.common.utils.HttpsUtils;
import com.jz.common.utils.RedisUtils;
import com.jz.dm.common.constant.Constants;
import com.jz.dm.common.constant.TagConstants;
import com.jz.dm.common.enums.GatewayResultCode;
import com.jz.dm.common.enums.apiInterface.ApiStatusEnum;
import com.jz.dm.common.enums.auth.AuthReqTypeEnum;
......@@ -89,7 +90,11 @@ public class AuthFilter extends AbstractFilter {
}
}
JSONObject parameter = JSONObject.parseObject(request.getParams());
if (null != parameter) {
if (null == parameter) {
throw new GatewayException(GatewayResultCode.REQUEST_PARAM_EMPTY);
}
Boolean isTest = parameter.getBoolean("isTest");
if (!isTest) {//是否测试数据
String authCode = parameter.getString("authCode");
ApiAuth authAuth = authService.getAuthUser(authCode, apiInterface.getId());
if (null == authAuth) {
......@@ -107,7 +112,7 @@ public class AuthFilter extends AbstractFilter {
if (!apiOrg.getStatus()) {
throw new GatewayException(GatewayResultCode.ORG_STATE_EXCEPTION);
}
checkBill(request, authCode, authAuth, apiOrg);
checkBill(request, authCode, authAuth);
}
chain.doFilter(request, response);
} catch (Exception e) {
......@@ -132,19 +137,17 @@ public class AuthFilter extends AbstractFilter {
* @param request
* @param authCode
* @param authAuth
* @param apiOrg
* @throws ParseException
*/
private void checkBill(GatewayRequest request, String authCode,
ApiAuth authAuth, ApiOrg apiOrg) throws ParseException {
ApiAuth authAuth) throws ParseException {
switch (authAuth.getAuthMode()) {
case "POWER_CALL_MODE": //按次调用
//查询数据银行银行余额是否充足
getDataAmountResult(request);
try { //记录请求次数(每天限制请求次数)
// String limitKey = TagConstants.OPEN_API_REDIS_LIMIT_KEY + authCode;
String limitKey = authCode;
String reqValue = (String)redisUtils.getObj(limitKey);
String limitKey = TagConstants.OPEN_API_REDIS_LIMIT_KEY + authCode;
Integer reqValue = (Integer) redisUtils.getObj(limitKey);
long timeOut = 0;
if (AuthReqTypeEnum.DAY.name().equals(authAuth.getReqType())) { //按天
timeOut = DateUtil.calculateNowResidueTime();
......@@ -154,11 +157,11 @@ public class AuthFilter extends AbstractFilter {
//暂时不支持年
}
if (null != reqValue) {
Integer value = Integer.valueOf(reqValue);
if (value > authAuth.getReqFrequency()) {//超出最大请求次数
/* Integer value = Integer.valueOf(reqValue);*/
if (reqValue > authAuth.getReqFrequency()) {//超出最大请求次数
throw new GatewayException(GatewayResultCode.REQUEST_LIMIT_EXCEPTION);
} else if (value <= authAuth.getReqFrequency()) {
redisUtils.delAndAdd(limitKey, limitKey, value + 1, timeOut);
} else if (reqValue <= authAuth.getReqFrequency()) {
redisUtils.delAndAdd(limitKey, limitKey, reqValue + 1, timeOut);
}
} else {
redisUtils.set(limitKey, 1, timeOut);
......@@ -217,7 +220,7 @@ public class AuthFilter extends AbstractFilter {
pObject.put("assetsId", assetsId);
pObject.put("userId", userId);
pObject.put("dataPrice", dataPrice);
String respResult = httpUtils.submitPost(balanceUrl+"/mall/financeCustomerAssets/findAssets", pObject.toString());
String respResult = httpUtils.submitPost(balanceUrl + "/mall/financeCustomerAssets/findAssets", pObject.toString());
JSONObject result = JSONObject.parseObject(respResult);
if (null != result) {
if (200 != result.getInteger("code")) {
......
......@@ -41,22 +41,25 @@ public class VerifySignFilter extends AbstractFilter {
protected void internalDoFilter(GatewayRequest request, GatewayResponse response,
FilterChain chain) {
try {
//对签约参数进行字典排序
String signParams = MapUtil.getSignValue(request.getApiKey(),request.getMethod(),request.getSignType());
if (StringUtils.isNotBlank(signParams)){
JSONObject jsonObject = JSONObject.parseObject(request.getParams());
String authCode = jsonObject.getString("authCode");
//需要传入授权码
ApiAuth apiAuthInfo = apiInterfaceService.getApiAuthInfo(request.getApiKey(),authCode );
if (null == apiAuthInfo){
throw new GatewayException(GatewayResultCode.ILLEGAL_REQUEST);
}
String sign = Md5.encrypt(signParams, apiAuthInfo.getSalt());
if (!request.getSign().equals(sign)){
JSONObject jsonObject = JSONObject.parseObject(request.getParams());
if (!jsonObject.getBoolean("isTest")){//是否测试调用
//对签约参数进行字典排序
String signParams = MapUtil.getSignValue(request.getApiKey(),request.getMethod(),request.getSignType());
if (StringUtils.isNotBlank(signParams)){
String authCode = jsonObject.getString("authCode");
//需要传入授权码
ApiAuth apiAuthInfo = apiInterfaceService.getApiAuthInfo(request.getApiKey(),authCode );
if (null == apiAuthInfo){
throw new GatewayException(GatewayResultCode.ILLEGAL_REQUEST);
}
String sign = Md5.encrypt(signParams, apiAuthInfo.getSalt());
if (!request.getSign().equals(sign)){
throw new GatewayException(GatewayResultCode.SIGN_ERROR);
}
}else {
throw new GatewayException(GatewayResultCode.SIGN_ERROR);
}
}else {
throw new GatewayException(GatewayResultCode.SIGN_ERROR);
}
chain.doFilter(request, response);
} catch (SignatureException ex) {
......
......@@ -66,6 +66,11 @@ public class ApiInterface extends BaseObject implements Serializable {
*/
@TableField("target_url")
private String targetUrl;
/**
* 请求方式:GET POST
*/
@TableField("req_method")
private String reqMethod;
/**
* 接入类型:对应字典表key
*/
......
......@@ -93,5 +93,15 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
*/
@TableField("inbox_param")
private String inboxParam;
/**
* 当前页
*/
@TableField("page_num")
private Integer pageNum;
/**
* 当前页显示数据
*/
@TableField("page_size")
private Integer pageSize;
}
......@@ -40,6 +40,9 @@ public class ApiInterfaceReq implements Serializable {
@NotNull(message="目标地址不能为空")
public String targetUrl;
@ApiModelProperty(value = "请求方式:GET POST",required = false)
public String reqMethod;
@ApiModelProperty(value = "超时时间",required = true)
@NotNull(message="超时时间不能为空")
public String timeout;
......@@ -54,7 +57,7 @@ public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "api描述",required = false)
public String apiFunction;
@ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = false)
/* @ApiModelProperty(value = "父类文件id,一级文件夹传入0",required = false)
public Long parentId;
@ApiModelProperty(value = "文件id",required = false)
......@@ -62,7 +65,7 @@ public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "项目id",required = true)
@NotNull(message="项目id不能为空")
public Long projectId;
public Long projectId;*/
@ApiModelProperty(value = "状态",required = false)
......
......@@ -40,9 +40,13 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "输出类型不能为空")
public String outputType;
@ApiModelProperty(value = "是否分页:",required = true)
@ApiModelProperty(value = "请求方式:GET POST",required = true)
@NotNull(message = "请求方式不能为空")
public String reqMethod;
/*@ApiModelProperty(value = "是否分页:",required = true)
@NotNull(message = "是否分页不能为空")
public Boolean page;
public Boolean page;*/
@ApiModelProperty(value = "限流类型:DAY 按天,MONTH 按月",required = true)
@NotNull(message = "限流类型不能为空")
......@@ -52,9 +56,15 @@ public class MakeDataBankApiReq implements Serializable {
@NotNull(message = "目标地址不能为空")
public String targetUrl;
@ApiModelProperty(value = "文件id",required = true)
@NotNull(message = "文件id不能为空")
public Long fileId;
@ApiModelProperty(value = "当前页",required = true)
public Integer pageNum;
@ApiModelProperty(value = "当前页显示条数",required = true)
public Integer pageSize;
//@ApiModelProperty(value = "文件id",required = true)
//@NotNull(message = "文件id不能为空")
//public Long fileId;
@ApiModelProperty(value = "签名",required = true)
@NotNull(message = "签名不能为空")
......@@ -69,7 +79,8 @@ public class MakeDataBankApiReq implements Serializable {
@ApiModelProperty(value = "接口描述",required = false)
public String apiDesc;
@ApiModelProperty(value = "数据包下载路径",required = false)
public String fileLocation;
@ApiModelProperty(value = "超时时间",required = false)
public String timeout;
......
......@@ -146,13 +146,13 @@ public class ProducerServiceImpl implements ProducerService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
public Result addDataBankApiInfo(MakeDataBankApiReq req) {
QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
/* QueryWrapper<ApiInterfaceFile> query = new QueryWrapper<>();
query.eq("file_source", "2");
query.eq("is_deleted", 0);
List<ApiInterfaceFile> fileSource = apiInterfaceFileMapper.selectList(query);
if (fileSource.size() == 0 || fileSource.size() >= 2) {
return Result.of_error("文件夹信息异常!");
}
}*/
if (StringUtils.isNotBlank(req.getOutputType())) {
if (!req.getOutputType().contains(ApiInfoOutTypeEnum.JSON.name()) ||
!req.getOutputType().contains(ApiInfoOutTypeEnum.FLOW.name())) {
......@@ -175,6 +175,7 @@ public class ProducerServiceImpl implements ProducerService {
saveDataBanker(req, apiKey, "3");
break;
case "10007"://数据银行数据包上传
if(StringUtils.isNotBlank(req.getFileLocation()))return Result.of_error("文件地址不存在!");
saveDataBanker(req, apiKey, "2");
break;
case "10008"://数据银行制作大数据表
......@@ -199,6 +200,7 @@ public class ProducerServiceImpl implements ProducerService {
JSONObject object = new JSONObject();
object.put("targetUrl", req.getTargetUrl());
object.put("outputType", req.getOutputType());
object.put("reqMethod",req.getReqMethod());
saveObjOnRedis(apiInterface.getApiKey(), object);
}
......@@ -340,10 +342,10 @@ public class ProducerServiceImpl implements ProducerService {
//生成ApiKey
String apiKey = getApiKey();
ApiInterface apiInterface = new ApiInterface();
if (null == req.getFileId()) {//创建下级文件夹
/* if (null == req.getFileId()) {//创建下级文件夹
Long fileId = checkFileExist(req.getProjectId(), req.getParentId(), req.getCreateUser());
req.setFileId(fileId);
}
}*/
BeanUtils.copyProperties(req, apiInterface);
apiInterface.setApiKey(apiKey);
apiInterface.setApiProtocl(req.getTransMode());//传输方式 https http
......
......@@ -107,5 +107,8 @@ logging:
zhl:
springbootlogback: off
#数据包访问链接
dataPackage:
downloadUrl: http://xxx.com
......@@ -43,10 +43,10 @@ public class TestRedisUserSave extends SpringTestCase {
bankApiReq.setSignType("MD5");
bankApiReq.setJoinType("10004");
bankApiReq.setOutputType("JSON");
bankApiReq.setPage(false);
//bankApiReq.setPage(false);
bankApiReq.setReqType("DAY");
bankApiReq.setTargetUrl("www.baidu.com");
bankApiReq.setFileId(1L);
//bankApiReq.setFileId(1L);
bankApiReq.setSign("F2A8E3CFE528D6AE5C5B075046653F3E");
bankApiReq.setReqFrequency(0L);
bankApiReq.setApiDesc("4444");
......
package com.jz.dm.gateway.orther;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @ClassName:
* @Author: Carl
......@@ -8,10 +12,62 @@ package com.jz.dm.gateway.orther;
*/
public class TestStr {
public static void main(String[] args) {
String str = "/picture/logo/T6gxlv137nFA555z.jpg";
// String[] split = str.split("\\/");
System.out.println(str.substring(0, str.lastIndexOf("/") + 1));
String substring = str.substring(str.lastIndexOf("."));
System.out.println(substring);
List<String> list1 = new ArrayList<String>();
list1.add("1");
list1.add("2");
list1.add("3");
list1.add("4");
list1.add("5");
List<String> list2 = new ArrayList<String>();
list2.add("1");
list2.add("2");
list2.add("3");
list2.add("4");
list2.add("5");
list2.add("7");
list2.add("9");
// 交集
List<String> intersection = list1.stream().filter(item -> list2.contains(item)).collect(Collectors.toList());
System.out.println("---交集 intersection---");
intersection.parallelStream().forEach(System.out :: println);
// 差集 (list1 - list2)
List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(Collectors.toList());
System.out.println("---差集 reduce1 (list1 - list2)---");
reduce1.parallelStream().forEach(System.out :: println);
// 差集 (list2 - list1)
List<String> reduce2 = list2.stream().filter(item -> !list1.contains(item)).collect(Collectors.toList());
System.out.println("---差集 reduce2 (list2 - list1)---");
reduce2.parallelStream().forEach(System.out :: println);
//合拼差
reduce1.addAll(reduce2);
System.out.println("---合拼差 reduce1 (list2 -> list1)---");
reduce1.parallelStream().forEach(System.out :: println);
// 并集
List<String> listAll = list1.parallelStream().collect(Collectors.toList());
List<String> listAll2 = list2.parallelStream().collect(Collectors.toList());
listAll.addAll(listAll2);
System.out.println("---并集 listAll---");
listAll.parallelStream().forEachOrdered(System.out :: println);
// 去重并集
List<String> listAllDistinct = listAll.stream().distinct().collect(Collectors.toList());
System.out.println("---得到去重并集 listAllDistinct---");
listAllDistinct.parallelStream().forEachOrdered(System.out :: println);
System.out.println("---原来的List1---");
list1.parallelStream().forEachOrdered(System.out :: println);
System.out.println("---原来的List2---");
list2.parallelStream().forEachOrdered(System.out :: println);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment