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
1fbaa1fb
Commit
1fbaa1fb
authored
Jan 10, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单位
parent
e5b1c795
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
15 deletions
+19
-15
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+12
-10
src/main/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
...ain/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
+3
-1
src/main/java/com/zksy/szpt/util/SignatureUtil.java
src/main/java/com/zksy/szpt/util/SignatureUtil.java
+1
-0
src/test/java/com/zksy/szpt/TestHttpUtil.java
src/test/java/com/zksy/szpt/TestHttpUtil.java
+3
-4
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
1fbaa1fb
...
@@ -80,10 +80,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -80,10 +80,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
String
nonce
=
request
.
getHeader
(
SignatureUtil
.
NONCE
);
String
nonce
=
request
.
getHeader
(
SignatureUtil
.
NONCE
);
// 时间戳
// 时间戳
String
timestampStr
=
request
.
getHeader
(
SignatureUtil
.
TIMESTAMP
);
String
timestampStr
=
request
.
getHeader
(
SignatureUtil
.
TIMESTAMP
);
// 单位
String
deptCode
=
request
.
getHeader
(
SignatureUtil
.
DEPT_CODE
);
if
(!
StringUtils
.
hasText
(
appId
)
||
!
StringUtils
.
hasText
(
sign
)
||
!
StringUtils
.
hasText
(
nonce
)
||
!
StringUtils
.
hasText
(
timestampStr
))
{
if
(!
StringUtils
.
hasText
(
appId
)
||
!
StringUtils
.
hasText
(
sign
)
||
!
StringUtils
.
hasText
(
nonce
)
||
!
StringUtils
.
hasText
(
timestampStr
)
||
!
StringUtils
.
hasText
(
deptCode
)
)
{
logger
.
warn
(
"缺少参数appId:{},sign:{},nonce{},timestampStr:{}
"
,
appId
,
sign
,
nonce
,
timestampStr
);
logger
.
warn
(
"缺少参数appId:{},sign:{},nonce{},timestampStr:{}
,deptCode:{}"
,
appId
,
sign
,
nonce
,
timestampStr
,
deptCode
);
this
.
write
(
response
,
"请求头缺少参数,appId:"
+
appId
+
",sign:"
+
sign
+
",nonce:"
+
nonce
+
",timestamp:"
+
timestampStr
);
this
.
write
(
response
,
"请求头缺少参数,appId:"
+
appId
+
",sign:"
+
sign
+
",nonce:"
+
nonce
+
",timestamp:"
+
timestampStr
+
",deptCode:"
+
deptCode
);
return
false
;
return
false
;
}
}
...
@@ -125,21 +127,21 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -125,21 +127,21 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
Map
<
String
,
Object
>
objectMap
=
objectMapper
.
readValue
(
body
,
Map
.
class
);
Map
<
String
,
Object
>
objectMap
=
objectMapper
.
readValue
(
body
,
Map
.
class
);
//验证单位
//验证单位
if
(
objectMap
.
get
(
"sjgsdwdm"
)
!=
null
&&
!
objectMap
.
get
(
"sjgsdwdm"
).
toString
()
.
startsWith
(
appStore
.
getDeptCode
().
replaceAll
(
"0+$"
,
""
)))
{
if
(
!
deptCode
.
startsWith
(
appStore
.
getDeptCode
().
replaceAll
(
"0+$"
,
""
)))
{
write
(
response
,
"AppId和传入的单位不匹配,appId:"
+
appId
+
",deptCode:"
+
objectMap
.
get
(
"deptCode"
));
write
(
response
,
"AppId和传入的单位不匹配,appId:"
+
appId
+
",deptCode:"
+
objectMap
.
get
(
"deptCode"
));
return
false
;
return
false
;
}
}
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}
"
,
appId
,
nonce
,
timestampStr
,
body
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}
, deptCode: {}"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
// logger.info("appSecret{}加密后body: {}", appSecret,body);
// logger.info("appSecret{}加密后body: {}", appSecret,body);
// 校验签名appId+nonce+timestampStr+aes(body,secret)
// 校验签名appId+nonce+timestampStr+aes(body,secret)
+detCode
String
data
=
String
.
format
(
"%s%s%s%s
"
,
appId
,
nonce
,
timestampStr
,
body
);
String
data
=
String
.
format
(
"%s%s%s%s
%s"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
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:{}
,deptCode:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
,
deptCode
);
write
(
response
,
"签名有误,sign: "
+
sign
+
",appId: "
+
appId
+
",nonce: "
+
nonce
+
",timestamp: "
+
timestampStr
);
write
(
response
,
"签名有误,sign: "
+
sign
+
",appId: "
+
appId
+
",nonce: "
+
nonce
+
",timestamp: "
+
timestampStr
+
",deptCode:"
+
deptCode
);
return
false
;
return
false
;
}
}
...
@@ -173,7 +175,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
...
@@ -173,7 +175,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
// 增加用户信息
// 增加用户信息
String
userId
=
request
.
getHeader
(
SignatureUtil
.
APPID
);
String
userId
=
request
.
getHeader
(
SignatureUtil
.
APPID
);
String
ip
=
request
.
getRemoteAddr
();
String
ip
=
request
.
getRemoteAddr
();
CurrentUserInfo
currentUserInfo
=
new
CurrentUserInfo
.
CurrentUserInfoBuilder
().
userId
(
userId
).
userName
(
userId
).
ip
(
ip
).
build
();
CurrentUserInfo
currentUserInfo
=
new
CurrentUserInfo
.
CurrentUserInfoBuilder
().
userId
(
userId
).
userName
(
userId
).
ip
(
ip
).
deptCode
(
request
.
getHeader
(
SignatureUtil
.
DEPT_CODE
)).
build
();
UserContextHolder
.
set
(
currentUserInfo
);
UserContextHolder
.
set
(
currentUserInfo
);
}
}
}
}
...
...
src/main/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
View file @
1fbaa1fb
...
@@ -28,6 +28,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
...
@@ -28,6 +28,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
CurrentUserInfo
currentUserInfo
=
UserContextHolder
.
get
();
CurrentUserInfo
currentUserInfo
=
UserContextHolder
.
get
();
if
(
currentUserInfo
==
null
)
{
if
(
currentUserInfo
==
null
)
{
log
.
error
(
"当前用户信息为空,无法自动填充 create_time, update_time 字段"
);
log
.
error
(
"当前用户信息为空,无法自动填充 create_time, update_time 字段"
);
return
;
}
}
List
<
StrictFill
>
fields
=
Arrays
.
asList
(
List
<
StrictFill
>
fields
=
Arrays
.
asList
(
...
@@ -35,7 +36,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
...
@@ -35,7 +36,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
StrictFill
.
of
(
"cjsj"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"cjsj"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"gxsj"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"gxsj"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"updateTime"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"updateTime"
,
Date
.
class
,
new
Date
()),
// StrictFill.of("sjgsdwdm", String.class, "1"
),
StrictFill
.
of
(
"sjgsdwdm"
,
String
.
class
,
currentUserInfo
.
getDeptCode
()
),
// StrictFill.of("sjgsdwmc", String.class, "1"),
// StrictFill.of("sjgsdwmc", String.class, "1"),
StrictFill
.
of
(
"createGajgjgdm"
,
String
.
class
,
"1"
),
StrictFill
.
of
(
"createGajgjgdm"
,
String
.
class
,
"1"
),
StrictFill
.
of
(
"createGajgmc"
,
String
.
class
,
"1"
),
StrictFill
.
of
(
"createGajgmc"
,
String
.
class
,
"1"
),
...
@@ -59,6 +60,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
...
@@ -59,6 +60,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
CurrentUserInfo
currentUserInfo
=
UserContextHolder
.
get
();
CurrentUserInfo
currentUserInfo
=
UserContextHolder
.
get
();
if
(
currentUserInfo
==
null
)
{
if
(
currentUserInfo
==
null
)
{
log
.
error
(
"当前用户信息为空,无法自动填充 update_time 字段"
);
log
.
error
(
"当前用户信息为空,无法自动填充 update_time 字段"
);
return
;
}
}
List
<
StrictFill
>
fields
=
Arrays
.
asList
(
List
<
StrictFill
>
fields
=
Arrays
.
asList
(
StrictFill
.
of
(
"updateTime"
,
Date
.
class
,
new
Date
()),
StrictFill
.
of
(
"updateTime"
,
Date
.
class
,
new
Date
()),
...
...
src/main/java/com/zksy/szpt/util/SignatureUtil.java
View file @
1fbaa1fb
...
@@ -5,4 +5,5 @@ public class SignatureUtil {
...
@@ -5,4 +5,5 @@ public class SignatureUtil {
public
static
String
TIMESTAMP
=
"x-szpt-timestamp"
;
public
static
String
TIMESTAMP
=
"x-szpt-timestamp"
;
public
static
String
NONCE
=
"x-szpt-nonce"
;
public
static
String
NONCE
=
"x-szpt-nonce"
;
public
static
String
APPID
=
"x-szpt-appid"
;
public
static
String
APPID
=
"x-szpt-appid"
;
public
static
String
DEPT_CODE
=
"x-szpt-dept_code"
;
}
}
src/test/java/com/zksy/szpt/TestHttpUtil.java
View file @
1fbaa1fb
...
@@ -32,12 +32,10 @@ public class TestHttpUtil {
...
@@ -32,12 +32,10 @@ public class TestHttpUtil {
}
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)+deptCode
//签名appId+nonce+timestampStr+aes(body)
String
data
=
String
.
format
(
"%s%s%s%s%S"
,
appId
,
nonce
,
timestampStr
,
json
,
deptCode
);
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
json
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
//请求
//请求
WebClient
webClient
=
WebClient
.
builder
()
WebClient
webClient
=
WebClient
.
builder
()
...
@@ -49,6 +47,7 @@ public class TestHttpUtil {
...
@@ -49,6 +47,7 @@ public class TestHttpUtil {
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
header
(
SignatureUtil
.
DEPT_CODE
,
deptCode
)
.
body
(
Mono
.
just
(
source
),
destinationClass
)
.
body
(
Mono
.
just
(
source
),
destinationClass
)
.
retrieve
()
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
bodyToMono
(
String
.
class
)
...
...
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