Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
dm_project
Commits
34d738b8
Commit
34d738b8
authored
Jan 29, 2021
by
ysongq
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dm_dev' into dm_dev
parents
175302c3
49bc0f72
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
46 additions
and
45 deletions
+46
-45
api_gateway.sql
database/zc/api_gateway.sql
+1
-1
HttpDownload.java
.../main/java/com/jz/dm/common/util/stream/HttpDownload.java
+8
-2
ApiInterface.java
...y/src/main/java/com/jz/dm/models/domian/ApiInterface.java
+2
-2
ApiInterfaceCustom.java
...main/java/com/jz/dm/models/domian/ApiInterfaceCustom.java
+3
-3
AuthUserApiReq.java
...c/main/java/com/jz/dm/models/req/auth/AuthUserApiReq.java
+0
-7
ApiInterfaceReq.java
...n/java/com/jz/dm/models/req/producer/ApiInterfaceReq.java
+1
-1
AuthServiceImpl.java
...src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
+1
-9
ProducerServiceImpl.java
...main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
+2
-2
ApiQueryService.java
.../main/java/com/jz/dm/service/request/ApiQueryService.java
+5
-8
ApiQueryTestService.java
...n/java/com/jz/dm/service/request/ApiQueryTestService.java
+14
-2
application-test.yml
jz-dm-apigateway/src/main/resources/application-test.yml
+1
-1
ApiReqTest.java
...teway/src/test/java/com/jz/dm/gateway/api/ApiReqTest.java
+8
-7
No files found.
database/zc/api_gateway.sql
View file @
34d738b8
...
...
@@ -12,7 +12,7 @@ CREATE TABLE `t_api_interface` (
`status`
varchar
(
50
)
NOT
NULL
COMMENT
'状态(DRAFT-草稿 ISSUE-发布 OUTMODED-过时 4FREEZE-冻结 EXPIRY-失效)'
,
`output_type`
varchar
(
50
)
NULL
DEFAULT
'JSON'
COMMENT
'输出类型:flow 流形式输出, json格式输出'
,
`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
'超时时间'
,
`file_id`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'文件夹id'
,
`limit_type`
varchar
(
20
)
DEFAULT
NULL
COMMENT
'限流类型:DAY 按天,MONTH 按月, YEAR 按年'
,
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/common/util/stream/HttpDownload.java
View file @
34d738b8
...
...
@@ -274,6 +274,7 @@ public class HttpDownload {
String
pdf
=
"http://192.168.1.140:8090/api/download/pdf"
;
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
postDownload
=
"http://192.168.1.140:8082/api/data/query/streaming1"
;
//String filepath = "C:\\Users\\key\\Desktop\\ideaIU-2019.3.3";
//HttpDownload.download(xlsx, null);
...
...
@@ -289,6 +290,11 @@ public class HttpDownload {
jsonObject
.
put
(
"response_fields"
,
"field1,field2,field3,field4"
);
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
);
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiInterface.java
View file @
34d738b8
...
...
@@ -87,10 +87,10 @@ public class ApiInterface extends BaseObject implements Serializable {
private
String
version
;
/**
* 加密方式:
MD5
RSA
* 加密方式:
0 无 1. MD5 2.
RSA
*/
@TableField
(
"sign_type"
)
private
String
signType
;
private
Integer
signType
;
/**
* 限流类型:DAY 按天,MONTH 按月, YEAR 按年
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/domian/ApiInterfaceCustom.java
View file @
34d738b8
...
...
@@ -55,11 +55,11 @@ public class ApiInterfaceCustom extends BaseObject implements Serializable {
@TableField
(
"es_table"
)
private
String
esTable
;
/**
/* */
/**
* 处理类型
*/
*/
/*
@TableField("handle_type")
private
String
handleType
;
private String handleType;
*/
/**
* api请求参数
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/auth/AuthUserApiReq.java
View file @
34d738b8
...
...
@@ -27,13 +27,6 @@ public class AuthUserApiReq implements Serializable {
@NotNull
(
message
=
"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
)
@NotNull
(
message
=
"组织编码不能为空"
)
private
String
orgCode
;
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/producer/ApiInterfaceReq.java
View file @
34d738b8
...
...
@@ -26,7 +26,7 @@ public class ApiInterfaceReq implements Serializable {
@ApiModelProperty
(
value
=
"加密方式0 无,1:MD5 2:RSA"
,
required
=
true
)
@NotNull
(
message
=
"加密方式不能为空"
)
public
String
signType
;
public
Integer
signType
;
@ApiModelProperty
(
value
=
"Api类型:对应字典表key"
,
required
=
true
)
@NotNull
(
message
=
"Api类型不能为空"
)
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
View file @
34d738b8
...
...
@@ -153,9 +153,6 @@ public class AuthServiceImpl implements AuthService {
!
AuthModeEnum
.
PERMANENT_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
()))
{
return
Result
.
of_error
(
"授权类型错误!"
);
}
if
(
StringUtils
.
isBlank
(
apiOrg
.
getOrgCode
()))
{
return
Result
.
of_error
(
"内部授权组织编码不能为空!!"
);
}
return
saveAuthInfo
(
apiInterface
,
apiOrg
,
req
);
}
...
...
@@ -206,10 +203,6 @@ public class AuthServiceImpl implements AuthService {
return
Result
.
of_error
(
"开始或结束时间不能为空!"
);
}
}
//验证用户id
if
(
StringUtils
.
isBlank
(
req
.
getUserId
()))
{
return
Result
.
of_error
(
"外部授权用户Id不能为空"
);
}
return
saveAuthInfo
(
apiInterface
,
apiOrg
,
req
);
}
...
...
@@ -228,7 +221,7 @@ public class AuthServiceImpl implements AuthService {
BeanUtils
.
copyProperties
(
req
,
apiAuth
);
apiAuth
.
setApiInterfaceId
(
apiInterface
.
getId
());
apiAuth
.
setApiOrgId
(
apiOrg
.
getId
());
apiAuth
.
setReqType
(
apiInterface
.
get
Req
Type
());
apiAuth
.
setReqType
(
apiInterface
.
get
Limit
Type
());
apiAuth
.
setReqFrequency
(
apiInterface
.
getReqFrequency
());
if
(!
AuthModeEnum
.
RECORD_TIME_MODE
.
name
().
equals
(
req
.
getAuthMode
())){
apiAuth
.
setValidExprDate
(
DateUtil
.
getAssignYearDate
(
99
));
//过期时间
...
...
@@ -240,7 +233,6 @@ public class AuthServiceImpl implements AuthService {
apiAuth
.
setAuthCode
(
authCode
);
//授权码
apiAuth
.
setSalt
(
salt
);
//盐值
apiAuth
.
setStatus
(
GeneralStatusTypeEnum
.
VALID
.
name
());
//授权状态
apiAuth
.
setCreateUser
(
req
.
getCreateUser
());
response
.
setAuthCode
(
authCode
);
response
.
setSalt
(
salt
);
if
(
apiAuthMapper
.
insert
(
apiAuth
)
>
0
)
{
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/ProducerServiceImpl.java
View file @
34d738b8
...
...
@@ -254,7 +254,7 @@ public class ProducerServiceImpl implements ProducerService {
return
Result
.
of_error
(
"限流次数不能小于或者等于零"
);
}
}
if
(
StringUtils
.
isBlank
(
req
.
getSignType
())
||
"0"
.
equals
(
req
.
getSignType
()
))
{
if
(
null
==
req
.
getSignType
()
||
0
==
req
.
getSignType
(
))
{
return
Result
.
of_error
(
"加密类型错误!"
);
}
if
(
StringUtils
.
isNotBlank
(
req
.
getLimitType
()))
{
...
...
@@ -342,7 +342,7 @@ public class ProducerServiceImpl implements ProducerService {
return
Result
.
of_error
(
"限流类型不存在!"
);
}
}
if
(
StringUtils
.
isBlank
(
req
.
getSignType
())
||
"0"
.
equals
(
req
.
getSignType
()
))
{
if
(
null
==
req
.
getSignType
()
||
0
==
req
.
getSignType
(
))
{
return
Result
.
of_error
(
"加密类型错误!"
);
}
if
(
null
!=
req
.
getReqFrequency
())
{
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/request/ApiQueryService.java
View file @
34d738b8
...
...
@@ -29,8 +29,6 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -72,7 +70,6 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
@Value
(
"${data.bank.balanceUrl}"
)
private
String
balanceUrl
;
/**
* API请求逻辑处理
*
...
...
@@ -106,8 +103,8 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
apiAuth
=
authService
.
getAuthInfo
(
authCode
);
verifyAuth
(
apiAuth
);
//取出缓存数据
/* String redisReqParam = redisUtils.get(request.getApiKey());*/
String
redisReqParam
=
null
;
String
redisReqParam
=
redisUtils
.
get
(
request
.
getApiKey
());
//
String redisReqParam = null;
if
(
StringUtils
.
isNotBlank
(
redisReqParam
))
{
//redis中存在
//解析出API制作成功时的参数配置
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
redisReqParam
);
...
...
@@ -281,16 +278,16 @@ public class ApiQueryService extends ApiParamVerify implements OpenApiService {
}
String
request$Filed
=
null
;
net
.
sf
.
json
.
JSONObject
reqParams
=
net
.
sf
.
json
.
JSONObject
.
fromObject
(
param
);
try
{
/*
try {
request$Filed = URLEncoder.encode(reqParams.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("流下载入参编码异常-------",e.getMessage());
}
}
*/
JSONObject
requestParams
=
new
JSONObject
();
requestParams
.
put
(
"datasourceId"
,
apiCustomInfo
.
getEsDataSource
());
requestParams
.
put
(
"query_database"
,
apiCustomInfo
.
getEsDataBase
());
requestParams
.
put
(
"query_table"
,
apiCustomInfo
.
getEsTable
());
requestParams
.
put
(
"request_fileds"
,
req
uest$Filed
);
requestParams
.
put
(
"request_fileds"
,
req
Params
);
requestParams
.
put
(
"response_fields"
,
assembleResponseParams
(
apiCustomInfo
.
getResponseParam
()));
requestParams
.
put
(
"data_size"
,
valueOf
);
HttpDownload
.
postDownload
(
targetUrl
,
requestParams
);
...
...
jz-dm-apigateway/src/main/java/com/jz/dm/service/request/ApiQueryTestService.java
View file @
34d738b8
package
com
.
jz
.
dm
.
service
.
request
;
import
com.alibaba.csp.sentinel.annotation.SentinelResource
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jz.common.utils.RedisUtils
;
import
com.jz.dm.common.enums.GatewayResultCode
;
...
...
@@ -57,6 +58,7 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
@AccessLimit
(
sec
=
1
,
limit
=
1000
)
@SentinelResource
(
value
=
"api.gatetest"
,
fallback
=
"fallbackGateway"
)
public
void
doService
(
OpenApiRequest
request
,
OpenApiResponse
response
)
{
JSONObject
parameter
=
JSONObject
.
parseObject
(
request
.
getOpenApiParams
());
ApiInterface
apiInterface
=
apiInterfaceService
.
getApiInfo
(
request
.
getApiKey
());
...
...
@@ -70,8 +72,8 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
jsonParams
.
put
(
"is_test"
,
true
);
}
//取出缓存数据
//
String redisReqParam = redisUtils.get(request.getApiKey());
String
redisReqParam
=
null
;
String
redisReqParam
=
redisUtils
.
get
(
request
.
getApiKey
());
//
String redisReqParam = null;
if
(
StringUtils
.
isNotBlank
(
redisReqParam
))
{
//redis中存在
//解析出API制作成功时的参数配置
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
redisReqParam
);
...
...
@@ -90,4 +92,14 @@ public class ApiQueryTestService extends ApiParamVerify implements OpenApiServic
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
);
}
}
jz-dm-apigateway/src/main/resources/application-test.yml
View file @
34d738b8
...
...
@@ -104,7 +104,7 @@ data:
balanceUrl
:
http://192.168.1.139:8081
#余额信息url #扣款信通知url
select
:
#大数据查询请求链接
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/streaming
1
#token: #dataBank 制作验签
# dataBank: dataBank123
...
...
jz-dm-apigateway/src/test/java/com/jz/dm/gateway/api/ApiReqTest.java
View file @
34d738b8
...
...
@@ -27,14 +27,15 @@ public class ApiReqTest extends SpringTestCase {
public
void
TestGatewayReq
()
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"apiKey"
,
"
8trDpp4WRl92850o
"
);
jsonObject
.
put
(
"apiKey"
,
"
fM59D6210E3K436m
"
);
jsonObject
.
put
(
"method"
,
"query"
);
jsonObject
.
put
(
"signType"
,
"MD5"
);
long
time
=
System
.
currentTimeMillis
();
jsonObject
.
put
(
"timestamp"
,
String
.
valueOf
(
time
));
String
date
=
String
.
valueOf
(
time
);
jsonObject
.
put
(
"timestamp"
,
date
);
JSONObject
params
=
new
JSONObject
();
params
.
put
(
"authCode"
,
"202100000001111810485
6J1QR4u9Afm
"
);
params
.
put
(
"authCode"
,
"202100000001111810485
20T38nzc5x7
"
);
params
.
put
(
"reqParams"
,
new
JSONObject
());
jsonObject
.
put
(
"params"
,
params
);
try
{
...
...
@@ -43,10 +44,10 @@ public class ApiReqTest extends SpringTestCase {
String
signType
=
jsonObject
.
getString
(
"signType"
);
String
signature
=
MapUtil
.
getSignValue
(
apiKey
,
method
,
signType
);
String
s
alt
=
Md5
.
encrypt
(
signature
,
"7330lQl2
"
);
jsonObject
.
put
(
"sign"
,
s
alt
);
String
response
=
httpsUtils
.
submitPost
(
url
,
jsonObject
.
toString
());
System
.
out
.
println
(
response
);
String
s
ign
=
Md5
.
encrypt
(
signature
,
"IE36FItU
"
);
jsonObject
.
put
(
"sign"
,
s
ign
);
/* String response = httpsUtils.submitPost(url, jsonObject.toString());*/
System
.
out
.
println
(
"时间戳为:"
+
date
+
"--签名为:{}"
+
sign
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment