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
89fb5350
Commit
89fb5350
authored
Jan 09, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
让数据归属单位字段前端传递
parent
1eff820d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
12 deletions
+24
-12
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+18
-8
src/test/java/com/zksy/szpt/MainTest.java
src/test/java/com/zksy/szpt/MainTest.java
+6
-4
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
89fb5350
...
...
@@ -100,19 +100,24 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
// 校验appId
AppStore
appStore
=
this
.
appStoreService
.
getAppSecretInfo
(
appId
);
String
secretKey
=
appStore
.
getAppSecret
();
if
(!
StringUtils
.
hasText
(
secretKey
))
{
String
appSecret
=
appStore
.
getAppSecret
();
if
(!
StringUtils
.
hasText
(
appSecret
))
{
this
.
write
(
response
,
"appId无效"
);
return
false
;
}
//验证单位 todo
// String deptCode = appStore.getDeptCode();
// 请求体
// post请求body
String
body
=
StreamUtils
.
copyToString
(
request
.
getInputStream
(),
StandardCharsets
.
UTF_8
);
body
=
objectMapper
.
writeValueAsString
(
objectMapper
.
readValue
(
body
,
Map
.
class
));
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
secretKey
);
Map
<
String
,
Object
>
objectMap
=
objectMapper
.
readValue
(
body
,
Map
.
class
);
//验证单位
if
(
objectMap
.
get
(
"deptCode"
)
!=
null
&&
!
objectMap
.
get
(
"sjgsdwdm"
).
toString
().
startsWith
(
appStore
.
getDeptCode
().
replaceAll
(
"0+$"
,
""
)))
{
write
(
response
,
"AppId和传入的单位不匹配,appId:"
+
appId
+
",deptCode:"
+
objectMap
.
get
(
"deptCode"
));
return
false
;
}
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
// 校验签名appId+nonce+timestampStr+aes(body,secret)
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
...
...
@@ -144,6 +149,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
/**
* 增加用户信息
*
* @param request
*/
private
void
addUserInfo
(
HttpServletRequest
request
)
{
...
...
@@ -153,5 +159,9 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
CurrentUserInfo
currentUserInfo
=
new
CurrentUserInfo
.
CurrentUserInfoBuilder
().
userId
(
userId
).
userName
(
userId
).
ip
(
ip
).
build
();
UserContextHolder
.
set
(
currentUserInfo
);
}
private
void
checkDeptCode
(
String
deptCode
,
AppStore
appStore
)
{
}
}
src/test/java/com/zksy/szpt/MainTest.java
View file @
89fb5350
...
...
@@ -28,7 +28,8 @@ public class MainTest {
String
nonce
=
"2"
;
String
timestampStr
=
"21"
;
String
appId
=
"1872476300466950146"
;
String
appId
=
"1872576325743943682"
;
String
appSecret
=
"2"
;
@Resource
...
...
@@ -45,8 +46,9 @@ public class MainTest {
public
void
xxRwwcqkTest
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
Assertions
.
assertNotNull
(
appId
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
XxRwwcqkDTO
xxRwwcqkDTO
=
new
XxRwwcqkDTO
();
xxRwwcqkDTO
.
setRwid
(
"123456"
);
...
...
@@ -61,7 +63,7 @@ public class MainTest {
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
appSecret
);
//签名appId+nonce+timestampStr+aes(body)
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
json
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
...
...
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