Commit 1909103c authored by zhangc's avatar zhangc

commit

parent 86d6f621
...@@ -12,7 +12,7 @@ CREATE TABLE `t_api_interface` ( ...@@ -12,7 +12,7 @@ CREATE TABLE `t_api_interface` (
`status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)', `status` varchar(50) NOT NULL COMMENT '状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)',
`output_type` varchar(50) NULL DEFAULT 'JSON' COMMENT '输出类型:flow 流形式输出, json格式输出', `output_type` varchar(50) NULL DEFAULT 'JSON' COMMENT '输出类型:flow 流形式输出, json格式输出',
`version` varchar(20) DEFAULT 'v1.0' COMMENT '版本号', `version` varchar(20) DEFAULT 'v1.0' COMMENT '版本号',
`sign_type` varchar(50) DEFAULT NULL COMMENT '加密方式: MD5 RSA', `sign_type` tinyint(2) DEFAULT NULL COMMENT '加密方式:0 无 1. MD5 2. RSA',
`timeout` varchar(50) DEFAULT NULL COMMENT '超时时间', `timeout` varchar(50) DEFAULT NULL COMMENT '超时时间',
`file_id` bigint(20) DEFAULT NULL COMMENT '文件夹id', `file_id` bigint(20) DEFAULT NULL COMMENT '文件夹id',
`limit_type` varchar(20) DEFAULT NULL COMMENT '限流类型:DAY 按天,MONTH 按月, YEAR 按年', `limit_type` varchar(20) DEFAULT NULL COMMENT '限流类型:DAY 按天,MONTH 按月, YEAR 按年',
......
...@@ -83,7 +83,7 @@ public class HttpDownload { ...@@ -83,7 +83,7 @@ public class HttpDownload {
try { try {
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type","application/json" ); httpPost.setHeader("Content-Type","application/json" );
if (StringUtils.isNotBlank(params.toString())) { if (StringUtils.isNotBlank(params.toString())) {
httpPost.setEntity(new StringEntity(params.toString(), Consts.UTF_8)); httpPost.setEntity(new StringEntity(params.toString(), Consts.UTF_8));
} }
...@@ -274,6 +274,7 @@ public class HttpDownload { ...@@ -274,6 +274,7 @@ public class HttpDownload {
String pdf = "http://192.168.1.140:8090/api/download/pdf"; String pdf = "http://192.168.1.140:8090/api/download/pdf";
String xlsx = "http://192.168.1.140:8090/api/download/xlsx"; String xlsx = "http://192.168.1.140:8090/api/download/xlsx";
String getDownload ="http://192.168.1.140:8082/api/data/query/streaming?datasourceId=2&query_database=product&query_table=table1&request_fileds=%7b%22flelds1%22:%20%22xxxx%22,%20%22field2%22:%22xxxx%22%7d&response_fields=field1,field2,field3,field4&data_size=100"; String getDownload ="http://192.168.1.140:8082/api/data/query/streaming?datasourceId=2&query_database=product&query_table=table1&request_fileds=%7b%22flelds1%22:%20%22xxxx%22,%20%22field2%22:%22xxxx%22%7d&response_fields=field1,field2,field3,field4&data_size=100";
String postDownload="http://192.168.1.140:8082/api/data/query/streaming1"; String postDownload="http://192.168.1.140:8082/api/data/query/streaming1";
//String filepath = "C:\\Users\\key\\Desktop\\ideaIU-2019.3.3"; //String filepath = "C:\\Users\\key\\Desktop\\ideaIU-2019.3.3";
//HttpDownload.download(xlsx, null); //HttpDownload.download(xlsx, null);
...@@ -289,6 +290,11 @@ public class HttpDownload { ...@@ -289,6 +290,11 @@ public class HttpDownload {
jsonObject.put("response_fields","field1,field2,field3,field4"); jsonObject.put("response_fields","field1,field2,field3,field4");
jsonObject.put("data_size",100); jsonObject.put("data_size",100);
postDownloadFolder(postDownload,jsonObject,null); // postDownloadFolder(postDownload,jsonObject,null);
String parameters ="{\"data_size\":-1,\"request_fileds\":{\"flelds1\":\"xxxxxx\",\"flelds2\":\"xxxxxx\"},\"datasourceId\":\"1\",\"query_database\":\"product\",\"response_fields\":\"field1,field2,field3,field4\",\"query_table\":\"table1\"}\n";
JSONObject jsonObject2 = JSONObject.parseObject(parameters);
postDownloadFolder(postDownload,jsonObject2,null);
} }
} }
...@@ -87,10 +87,10 @@ public class ApiInterface extends BaseObject implements Serializable { ...@@ -87,10 +87,10 @@ public class ApiInterface extends BaseObject implements Serializable {
private String version; private String version;
/** /**
* 加密方式: MD5 RSA * 加密方式:0 无 1. MD5 2. RSA
*/ */
@TableField("sign_type") @TableField("sign_type")
private String signType; private Integer signType;
/** /**
* 限流类型:DAY 按天,MONTH 按月, YEAR 按年 * 限流类型:DAY 按天,MONTH 按月, YEAR 按年
......
...@@ -55,11 +55,11 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable { ...@@ -55,11 +55,11 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
@TableField("es_table") @TableField("es_table")
private String esTable; private String esTable;
/** /* *//**
* 处理类型 * 处理类型
*/ *//*
@TableField("handle_type") @TableField("handle_type")
private String handleType; private String handleType;*/
/** /**
* api请求参数 * api请求参数
......
...@@ -27,13 +27,6 @@ public class AuthUserApiReq implements Serializable { ...@@ -27,13 +27,6 @@ public class AuthUserApiReq implements Serializable {
@NotNull(message = "apiKey唯一标识不能为空") @NotNull(message = "apiKey唯一标识不能为空")
private String apiKey; private String apiKey;
//@ApiModelProperty(value = "组织类型: INT 内部, OUT 外部",required = true)
//@NotNull(message = "组织类型不能为空")
//private String orgType;
@ApiModelProperty(value = "用户id-- 数据银行认证时必传",required = false)
private String userId;
@ApiModelProperty(value = "组织编码",required = true) @ApiModelProperty(value = "组织编码",required = true)
@NotNull(message = "组织编码不能为空") @NotNull(message = "组织编码不能为空")
private String orgCode; private String orgCode;
......
...@@ -26,7 +26,7 @@ public class ApiInterfaceReq implements Serializable { ...@@ -26,7 +26,7 @@ public class ApiInterfaceReq implements Serializable {
@ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true) @ApiModelProperty(value = "加密方式0 无,1:MD5 2:RSA",required = true)
@NotNull(message = "加密方式不能为空") @NotNull(message = "加密方式不能为空")
public String signType; public Integer signType;
@ApiModelProperty(value = "Api类型:对应字典表key",required = true) @ApiModelProperty(value = "Api类型:对应字典表key",required = true)
@NotNull(message = "Api类型不能为空") @NotNull(message = "Api类型不能为空")
......
...@@ -153,9 +153,6 @@ public class AuthServiceImpl implements AuthService { ...@@ -153,9 +153,6 @@ public class AuthServiceImpl implements AuthService {
!AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) { !AuthModeEnum.PERMANENT_TIME_MODE.name().equals(req.getAuthMode())) {
return Result.of_error("授权类型错误!"); return Result.of_error("授权类型错误!");
} }
if (StringUtils.isBlank(apiOrg.getOrgCode())) {
return Result.of_error("内部授权组织编码不能为空!!");
}
return saveAuthInfo(apiInterface, apiOrg, req); return saveAuthInfo(apiInterface, apiOrg, req);
} }
...@@ -206,10 +203,6 @@ public class AuthServiceImpl implements AuthService { ...@@ -206,10 +203,6 @@ public class AuthServiceImpl implements AuthService {
return Result.of_error("开始或结束时间不能为空!"); return Result.of_error("开始或结束时间不能为空!");
} }
} }
//验证用户id
if (StringUtils.isBlank(req.getUserId())) {
return Result.of_error("外部授权用户Id不能为空");
}
return saveAuthInfo(apiInterface, apiOrg, req); return saveAuthInfo(apiInterface, apiOrg, req);
} }
...@@ -228,7 +221,7 @@ public class AuthServiceImpl implements AuthService { ...@@ -228,7 +221,7 @@ public class AuthServiceImpl implements AuthService {
BeanUtils.copyProperties(req, apiAuth); BeanUtils.copyProperties(req, apiAuth);
apiAuth.setApiInterfaceId(apiInterface.getId()); apiAuth.setApiInterfaceId(apiInterface.getId());
apiAuth.setApiOrgId(apiOrg.getId()); apiAuth.setApiOrgId(apiOrg.getId());
apiAuth.setReqType(apiInterface.getReqType()); apiAuth.setReqType(apiInterface.getLimitType());
apiAuth.setReqFrequency(apiInterface.getReqFrequency()); apiAuth.setReqFrequency(apiInterface.getReqFrequency());
if (!AuthModeEnum.RECORD_TIME_MODE.name().equals(req.getAuthMode())){ if (!AuthModeEnum.RECORD_TIME_MODE.name().equals(req.getAuthMode())){
apiAuth.setValidExprDate(DateUtil.getAssignYearDate(99));//过期时间 apiAuth.setValidExprDate(DateUtil.getAssignYearDate(99));//过期时间
...@@ -240,7 +233,6 @@ public class AuthServiceImpl implements AuthService { ...@@ -240,7 +233,6 @@ public class AuthServiceImpl implements AuthService {
apiAuth.setAuthCode(authCode);//授权码 apiAuth.setAuthCode(authCode);//授权码
apiAuth.setSalt(salt);//盐值 apiAuth.setSalt(salt);//盐值
apiAuth.setStatus(GeneralStatusTypeEnum.VALID.name());//授权状态 apiAuth.setStatus(GeneralStatusTypeEnum.VALID.name());//授权状态
apiAuth.setCreateUser(req.getCreateUser());
response.setAuthCode(authCode); response.setAuthCode(authCode);
response.setSalt(salt); response.setSalt(salt);
if (apiAuthMapper.insert(apiAuth) > 0) { if (apiAuthMapper.insert(apiAuth) > 0) {
......
...@@ -254,7 +254,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -254,7 +254,7 @@ public class ProducerServiceImpl implements ProducerService {
return Result.of_error("限流次数不能小于或者等于零"); return Result.of_error("限流次数不能小于或者等于零");
} }
} }
if (StringUtils.isBlank(req.getSignType()) || "0".equals(req.getSignType())) { if (null == req.getSignType() || 0 ==req.getSignType()) {
return Result.of_error("加密类型错误!"); return Result.of_error("加密类型错误!");
} }
if (StringUtils.isNotBlank(req.getLimitType())) { if (StringUtils.isNotBlank(req.getLimitType())) {
...@@ -342,7 +342,7 @@ public class ProducerServiceImpl implements ProducerService { ...@@ -342,7 +342,7 @@ public class ProducerServiceImpl implements ProducerService {
return Result.of_error("限流类型不存在!"); return Result.of_error("限流类型不存在!");
} }
} }
if (StringUtils.isBlank(req.getSignType()) || "0".equals(req.getSignType())) { if (null == req.getSignType() || 0 == req.getSignType()) {
return Result.of_error("加密类型错误!"); return Result.of_error("加密类型错误!");
} }
if (null != req.getReqFrequency()) { if (null != req.getReqFrequency()) {
......
...@@ -29,8 +29,6 @@ import org.springframework.stereotype.Service; ...@@ -29,8 +29,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -72,7 +70,6 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService { ...@@ -72,7 +70,6 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
@Value("${data.bank.balanceUrl}") @Value("${data.bank.balanceUrl}")
private String balanceUrl; private String balanceUrl;
/** /**
* API请求逻辑处理 * API请求逻辑处理
* *
...@@ -106,8 +103,8 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService { ...@@ -106,8 +103,8 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
apiAuth = authService.getAuthInfo(authCode); apiAuth = authService.getAuthInfo(authCode);
verifyAuth(apiAuth); verifyAuth(apiAuth);
//取出缓存数据 //取出缓存数据
/* String redisReqParam = redisUtils.get(request.getApiKey());*/ String redisReqParam = redisUtils.get(request.getApiKey());
String redisReqParam = null; // String redisReqParam = null;
if (StringUtils.isNotBlank(redisReqParam)) {//redis中存在 if (StringUtils.isNotBlank(redisReqParam)) {//redis中存在
//解析出API制作成功时的参数配置 //解析出API制作成功时的参数配置
JSONObject jsonObject = JSONObject.parseObject(redisReqParam); JSONObject jsonObject = JSONObject.parseObject(redisReqParam);
...@@ -281,16 +278,16 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService { ...@@ -281,16 +278,16 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
} }
String request$Filed =null; String request$Filed =null;
net.sf.json.JSONObject reqParams = net.sf.json.JSONObject.fromObject(param); net.sf.json.JSONObject reqParams = net.sf.json.JSONObject.fromObject(param);
try { /* try {
request$Filed = URLEncoder.encode(reqParams.toString(), "UTF-8"); request$Filed = URLEncoder.encode(reqParams.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("流下载入参编码异常-------",e.getMessage()); log.error("流下载入参编码异常-------",e.getMessage());
} }*/
JSONObject requestParams = new JSONObject(); JSONObject requestParams = new JSONObject();
requestParams.put("datasourceId",apiCustomInfo.getEsDataSource()); requestParams.put("datasourceId",apiCustomInfo.getEsDataSource());
requestParams.put("query_database",apiCustomInfo.getEsDataBase()); requestParams.put("query_database",apiCustomInfo.getEsDataBase());
requestParams.put("query_table",apiCustomInfo.getEsTable()); requestParams.put("query_table",apiCustomInfo.getEsTable());
requestParams.put("request_fileds",request$Filed); requestParams.put("request_fileds",reqParams);
requestParams.put("response_fields",assembleResponseParams(apiCustomInfo.getResponseParam())); requestParams.put("response_fields",assembleResponseParams(apiCustomInfo.getResponseParam()));
requestParams.put("data_size",valueOf); requestParams.put("data_size",valueOf);
HttpDownload.postDownload(targetUrl,requestParams); HttpDownload.postDownload(targetUrl,requestParams);
......
package com.jz.dm.service.request; package com.jz.dm.service.request;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jz.common.utils.RedisUtils; import com.jz.common.utils.RedisUtils;
import com.jz.dm.common.enums.GatewayResultCode; import com.jz.dm.common.enums.GatewayResultCode;
...@@ -57,6 +58,7 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic ...@@ -57,6 +58,7 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
@Override @Override
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED) @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
@AccessLimit(sec = 1,limit = 1000) @AccessLimit(sec = 1,limit = 1000)
@SentinelResource(value = "api.gatetest", fallback = "fallbackGateway")
public void doService(OpenApiRequest request, OpenApiResponse response) { public void doService(OpenApiRequest request, OpenApiResponse response) {
JSONObject parameter = JSONObject.parseObject(request.getOpenApiParams()); JSONObject parameter = JSONObject.parseObject(request.getOpenApiParams());
ApiInterface apiInterface = apiInterfaceService.getApiInfo(request.getApiKey()); ApiInterface apiInterface = apiInterfaceService.getApiInfo(request.getApiKey());
...@@ -70,8 +72,8 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic ...@@ -70,8 +72,8 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
jsonParams.put("is_test",true); jsonParams.put("is_test",true);
} }
//取出缓存数据 //取出缓存数据
// String redisReqParam = redisUtils.get(request.getApiKey()); String redisReqParam = redisUtils.get(request.getApiKey());
String redisReqParam = null; //String redisReqParam = null;
if (StringUtils.isNotBlank(redisReqParam)) {//redis中存在 if (StringUtils.isNotBlank(redisReqParam)) {//redis中存在
//解析出API制作成功时的参数配置 //解析出API制作成功时的参数配置
JSONObject jsonObject = JSONObject.parseObject(redisReqParam); JSONObject jsonObject = JSONObject.parseObject(redisReqParam);
...@@ -90,4 +92,14 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic ...@@ -90,4 +92,14 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
apiInterface.getTargetUrl(), paramMap, jsonParams, apiInterface, response); apiInterface.getTargetUrl(), paramMap, jsonParams, apiInterface, response);
} }
} }
/**
* 限流返回方法
*
* @param request
* @param response
*/
public void fallbackGateway(OpenApiRequest request, OpenApiResponse response) {
log.info("用户请求过于频繁触发限流接口:ApiKey为:{}" + request.getApiKey());
throw new GatewayException(GatewayResultCode.RATE_LIMIT_EXCEEDED);
}
} }
...@@ -104,7 +104,7 @@ data: ...@@ -104,7 +104,7 @@ data:
balanceUrl: http://192.168.1.139:8081 #余额信息url #扣款信通知url balanceUrl: http://192.168.1.139:8081 #余额信息url #扣款信通知url
select: #大数据查询请求链接 select: #大数据查询请求链接
jsonUrl: http://192.168.1.140:8082/api/data/query/json jsonUrl: http://192.168.1.140:8082/api/data/query/json
flowUrl: http://192.168.1.140:8082/api/data/query/streaming flowUrl: http://192.168.1.140:8082/api/data/query/streaming1
#token: #dataBank 制作验签 #token: #dataBank 制作验签
# dataBank: dataBank123 # dataBank: dataBank123
......
...@@ -27,14 +27,15 @@ public class ApiReqTest extends SpringTestCase { ...@@ -27,14 +27,15 @@ public class ApiReqTest extends SpringTestCase {
public void TestGatewayReq() { public void TestGatewayReq() {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("apiKey", "8trDpp4WRl92850o"); jsonObject.put("apiKey", "fM59D6210E3K436m");
jsonObject.put("method", "query"); jsonObject.put("method", "query");
jsonObject.put("signType", "MD5"); jsonObject.put("signType", "MD5");
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
jsonObject.put("timestamp", String.valueOf(time)); String date = String.valueOf(time);
jsonObject.put("timestamp", date);
JSONObject params = new JSONObject(); JSONObject params = new JSONObject();
params.put("authCode", "2021000000011118104856J1QR4u9Afm"); params.put("authCode", "20210000000111181048520T38nzc5x7");
params.put("reqParams", new JSONObject()); params.put("reqParams", new JSONObject());
jsonObject.put("params",params); jsonObject.put("params",params);
try { try {
...@@ -43,10 +44,10 @@ public class ApiReqTest extends SpringTestCase { ...@@ -43,10 +44,10 @@ public class ApiReqTest extends SpringTestCase {
String signType = jsonObject.getString("signType"); String signType = jsonObject.getString("signType");
String signature = MapUtil.getSignValue(apiKey, method, signType); String signature = MapUtil.getSignValue(apiKey, method, signType);
String salt = Md5.encrypt(signature, "7330lQl2"); String sign = Md5.encrypt(signature, "IE36FItU");
jsonObject.put("sign", salt); jsonObject.put("sign", sign);
String response = httpsUtils.submitPost(url, jsonObject.toString()); /* String response = httpsUtils.submitPost(url, jsonObject.toString());*/
System.out.println(response); System.out.println("时间戳为:"+date+"--签名为:{}"+sign);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
......
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