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
72f05dd5
Commit
72f05dd5
authored
Jan 09, 2025
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
APPKEY
parent
2250347a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
146 additions
and
1 deletion
+146
-1
src/main/java/com/zksy/szpt/controller/AppStoreController.java
...ain/java/com/zksy/szpt/controller/AppStoreController.java
+6
-0
src/main/java/com/zksy/szpt/domain/dto/AppStoreDTO.java
src/main/java/com/zksy/szpt/domain/dto/AppStoreDTO.java
+13
-0
src/main/java/com/zksy/szpt/domain/po/AppStore.java
src/main/java/com/zksy/szpt/domain/po/AppStore.java
+10
-0
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+1
-1
src/main/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
...ain/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
+1
-0
src/main/java/com/zksy/szpt/service/AppStoreService.java
src/main/java/com/zksy/szpt/service/AppStoreService.java
+5
-0
src/test/java/com/zksy/szpt/TestAppStore.java
src/test/java/com/zksy/szpt/TestAppStore.java
+110
-0
No files found.
src/main/java/com/zksy/szpt/controller/AppStoreController.java
View file @
72f05dd5
...
...
@@ -32,4 +32,10 @@ public class AppStoreController {
public
Integer
insertAppStore
(
@RequestBody
@Valid
AppStoreDTO
appStoreDTO
)
{
return
appStoreService
.
insertAppStore
(
appStoreDTO
);
}
@ApiOperation
(
value
=
"更新appKey"
,
notes
=
"更新appKey"
)
@PostMapping
(
"/updateAppIdSecret"
)
public
Integer
updateAppStore
(
@RequestBody
@Valid
AppStoreDTO
appStoreDTO
)
{
return
appStoreService
.
updateAppStore
(
appStoreDTO
);
}
}
src/main/java/com/zksy/szpt/domain/dto/AppStoreDTO.java
View file @
72f05dd5
package
com
.
zksy
.
szpt
.
domain
.
dto
;
import
javax.validation.constraints.NotBlank
;
public
class
AppStoreDTO
{
private
Long
id
;
@NotBlank
private
String
appKey
;
@NotBlank
private
String
appSecret
;
private
String
deptCode
;
public
String
getDeptCode
()
{
return
deptCode
;
}
public
void
setDeptCode
(
String
deptCode
)
{
this
.
deptCode
=
deptCode
;
}
public
Long
getId
()
{
return
id
;
...
...
src/main/java/com/zksy/szpt/domain/po/AppStore.java
View file @
72f05dd5
...
...
@@ -14,6 +14,16 @@ public class AppStore {
@TableField
(
fill
=
FieldFill
.
INSERT
)
private
Date
createTime
;
private
String
deptCode
;
@TableField
(
fill
=
FieldFill
.
UPDATE
)
private
Date
updateTime
;
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Long
getId
()
{
return
id
;
...
...
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
72f05dd5
...
...
@@ -122,7 +122,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
Map
<
String
,
Object
>
objectMap
=
objectMapper
.
readValue
(
body
,
Map
.
class
);
//验证单位
if
(
objectMap
.
get
(
"
deptCode
"
)
!=
null
&&
!
objectMap
.
get
(
"sjgsdwdm"
).
toString
().
startsWith
(
appStore
.
getDeptCode
().
replaceAll
(
"0+$"
,
""
)))
{
if
(
objectMap
.
get
(
"
sjgsdwdm
"
)
!=
null
&&
!
objectMap
.
get
(
"sjgsdwdm"
).
toString
().
startsWith
(
appStore
.
getDeptCode
().
replaceAll
(
"0+$"
,
""
)))
{
write
(
response
,
"AppId和传入的单位不匹配,appId:"
+
appId
+
",deptCode:"
+
objectMap
.
get
(
"deptCode"
));
return
false
;
}
...
...
src/main/java/com/zksy/szpt/handler/SzptMetaObjectHandler.java
View file @
72f05dd5
...
...
@@ -13,6 +13,7 @@ import java.util.List;
/**
* 自动填充 create_time, update_time 字段
* 该类策略如下:有值则不填充,无值则填充写入值,
*/
@Component
public
class
SzptMetaObjectHandler
implements
MetaObjectHandler
{
...
...
src/main/java/com/zksy/szpt/service/AppStoreService.java
View file @
72f05dd5
...
...
@@ -41,4 +41,9 @@ public class AppStoreService {
}
return
null
;
}
public
Integer
updateAppStore
(
AppStoreDTO
appStoreDTO
)
{
AppStore
appStore
=
BeanMapperUtil
.
map
(
appStoreDTO
,
AppStore
.
class
);
return
appStoreMapper
.
update
(
appStore
,
new
LambdaQueryWrapper
<
AppStore
>().
eq
(
AppStore:
:
getAppKey
,
appStore
.
getAppKey
()));
}
}
src/test/java/com/zksy/szpt/TestAppStore.java
0 → 100644
View file @
72f05dd5
package
com
.
zksy
.
szpt
;
import
cn.hutool.crypto.digest.DigestUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.zksy.szpt.domain.dto.*
;
import
com.zksy.szpt.util.EncryptUtil
;
import
com.zksy.szpt.util.SignatureUtil
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.DisplayName
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Mono
;
import
javax.annotation.Resource
;
@SpringBootTest
()
public
class
TestAppStore
{
String
nonce
=
"2"
;
String
timestampStr
=
"21"
;
String
appId
=
"1872576325743943682"
;
String
appSecret
=
"2"
;
@Resource
private
ObjectMapper
objectMapper
;
/**
* 新增AppId
*/
@Test
@DisplayName
(
"新增AppId"
)
public
void
addAppId
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
Assertions
.
assertNotNull
(
appId
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
AppStoreDTO
appStoreDTO
=
new
AppStoreDTO
();
appStoreDTO
.
setAppKey
(
"us"
);
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"us"
));
appStoreDTO
.
setDeptCode
(
"123456"
);
String
json
=
null
;
try
{
json
=
objectMapper
.
writeValueAsString
(
appStoreDTO
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
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
);
//请求
WebClient
webClient
=
WebClient
.
builder
()
.
baseUrl
(
"http://localhost:8086"
)
.
defaultHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
String
response
=
webClient
.
post
().
uri
(
"/rest/appStore/insertAppStore"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
appStoreDTO
),
XxRwwcqkDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
@Test
@DisplayName
(
"更新AppId的密钥"
)
public
void
updateAppIdSecret
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
Assertions
.
assertNotNull
(
appId
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
AppStoreDTO
appStoreDTO
=
new
AppStoreDTO
();
appStoreDTO
.
setAppKey
(
"us"
);
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"us11"
));
String
json
=
null
;
try
{
json
=
objectMapper
.
writeValueAsString
(
appStoreDTO
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
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
);
//请求
WebClient
webClient
=
WebClient
.
builder
()
.
baseUrl
(
"http://localhost:8086"
)
.
defaultHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
String
response
=
webClient
.
post
().
uri
(
"/rest/appStore/updateAppIdSecret"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
appStoreDTO
),
XxRwwcqkDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
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