Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
szpt
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
以墨为白
szpt
Commits
7cc870f4
Commit
7cc870f4
authored
Jan 10, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
7be11259
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
5 deletions
+9
-5
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+3
-1
src/test/java/com/zksy/szpt/TestAppStore.java
src/test/java/com/zksy/szpt/TestAppStore.java
+2
-0
src/test/java/com/zksy/szpt/TestHttpUtil.java
src/test/java/com/zksy/szpt/TestHttpUtil.java
+4
-4
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
7cc870f4
...
@@ -131,13 +131,15 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -131,13 +131,15 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
}
}
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}"
,
appId
,
nonce
,
timestampStr
,
body
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
// logger.info("appSecret{}加密后body: {}", appSecret,body);
// 校验签名appId+nonce+timestampStr+aes(body,secret)
// 校验签名appId+nonce+timestampStr+aes(body,secret)
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
);
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
if
(!
generatedSignature
.
equals
(
sign
))
{
if
(!
generatedSignature
.
equals
(
sign
))
{
logger
.
warn
(
"签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
);
logger
.
warn
(
"签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
);
write
(
response
,
"签名有误,sign: "
+
sign
+
",appId:
"
+
appId
+
",nonce:"
+
nonce
+
",timestamp:
"
+
timestampStr
);
write
(
response
,
"签名有误,sign: "
+
sign
+
",appId:
"
+
appId
+
",nonce: "
+
nonce
+
",timestamp:
"
+
timestampStr
);
return
false
;
return
false
;
}
}
...
...
src/test/java/com/zksy/szpt/TestAppStore.java
View file @
7cc870f4
...
@@ -19,6 +19,8 @@ public class TestAppStore {
...
@@ -19,6 +19,8 @@ public class TestAppStore {
appStoreDTO
.
setAppKey
(
"us2"
);
appStoreDTO
.
setAppKey
(
"us2"
);
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"us"
));
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"us"
));
appStoreDTO
.
setDeptCode
(
"123456"
);
appStoreDTO
.
setDeptCode
(
"123456"
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/updateAppIdSecret"
,
appStoreDTO
,
AppStoreDTO
.
class
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/insertAppStore"
,
appStoreDTO
,
AppStoreDTO
.
class
);
TestHttpUtil
.
signatureAndRequest
(
"/rest/appStore/insertAppStore"
,
appStoreDTO
,
AppStoreDTO
.
class
);
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO);
// TestHttpUtil.signatureAndRequest("/rest/appStore/insertAppStore", appStoreDTO);
}
}
...
...
src/test/java/com/zksy/szpt/TestHttpUtil.java
View file @
7cc870f4
...
@@ -15,7 +15,7 @@ public class TestHttpUtil {
...
@@ -15,7 +15,7 @@ public class TestHttpUtil {
static
String
nonce
=
"2"
;
static
String
nonce
=
"2"
;
static
String
timestampStr
=
"21"
;
static
String
timestampStr
=
"21"
;
static
String
appId
=
"1872576325743943682"
;
static
String
appId
=
"1872576325743943682"
;
static
String
appSecret
=
"2"
;
static
String
appSecret
=
DigestUtil
.
md5Hex
(
"2"
);
;
static
String
deptCode
=
"330102"
;
static
String
deptCode
=
"330102"
;
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
@@ -25,16 +25,17 @@ public class TestHttpUtil {
...
@@ -25,16 +25,17 @@ public class TestHttpUtil {
Assertions
.
assertNotNull
(
path
,
"path不能为空"
);
Assertions
.
assertNotNull
(
path
,
"path不能为空"
);
Assertions
.
assertNotNull
(
source
,
"请求参数不能为空"
);
Assertions
.
assertNotNull
(
source
,
"请求参数不能为空"
);
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
());
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
String
json
=
null
;
String
json
=
null
;
try
{
try
{
json
=
objectMapper
.
writeValueAsString
(
source
);
json
=
objectMapper
.
writeValueAsString
(
source
);
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
Assertions
.
fail
(
"json序列化失败"
);
}
}
// log.info("请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}", appId, nonce, timestampStr, json);
//请求体加密
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
appSecret
);
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
appSecret
);
// log.info("{}加密后json: {}", appSecret,json);
//签名appId+nonce+timestampStr+aes(body)
//签名appId+nonce+timestampStr+aes(body)
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
json
);
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
json
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
...
@@ -61,7 +62,6 @@ public class TestHttpUtil {
...
@@ -61,7 +62,6 @@ public class TestHttpUtil {
Assertions
.
assertNotNull
(
source
,
"请求参数不能为空"
);
Assertions
.
assertNotNull
(
source
,
"请求参数不能为空"
);
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
String
json
=
null
;
String
json
=
null
;
try
{
try
{
json
=
objectMapper
.
writeValueAsString
(
source
);
json
=
objectMapper
.
writeValueAsString
(
source
);
...
...
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