Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a3a53293
authored
Oct 11, 2023
by
刘鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CI: 添加外部接口AK校验, 并且不在校验白名单内的接口不再放行
1 parent
7c3debd7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
project-gateway/src/main/java/com/dituhui/pea/gateway/utils/SignUtil.java
project-gateway/src/main/java/com/dituhui/pea/gateway/config/AuthFilter.java
View file @
a3a5329
This diff is collapsed.
Click to expand it.
project-gateway/src/main/java/com/dituhui/pea/gateway/utils/SignUtil.java
0 → 100644
View file @
a3a5329
/*
* Begin license text.
* Copyright (c) 2020 — 2021 Liu Xin && Zhang Lei lsy_xin@163.com
* All rights reserved
* End license text.
*/
package
com
.
dituhui
.
pea
.
gateway
.
utils
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
java.util.Map
;
/**
* @author zl
*/
public
class
SignUtil
{
/**
* 对输入参数签名
*
* @param params 参数
* @param secret 密钥
* @return
* @throws IOException
*/
public
static
String
signRequest
(
Map
<
String
,
String
>
params
,
String
secret
)
{
try
{
// 第一步:参数排序
String
[]
keys
=
params
.
keySet
().
toArray
(
new
String
[
0
]);
Arrays
.
sort
(
keys
);
// 第二步:把所有参数名和参数值串在一起
StringBuilder
query
=
new
StringBuilder
();
for
(
String
key
:
keys
)
{
String
value
=
params
.
get
(
key
);
if
(
StringUtils
.
isNotEmpty
(
key
)
&&
!
StringUtils
.
equalsIgnoreCase
(
key
,
"sign"
)
&&
StringUtils
.
isNotEmpty
(
value
))
{
query
.
append
(
key
).
append
(
value
);
}
}
// 第三步:使用MD5/HMAC加密
return
DigestUtils
.
md5Hex
(
query
.
toString
()
+
secret
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment