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
011ebb60
Commit
011ebb60
authored
Jan 10, 2025
by
夏敏伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://192.168.168.218/wcyuee/szpt
parents
bc6a3963
cf0d8e66
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
278 deletions
+42
-278
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+3
-1
src/test/java/com/zksy/szpt/MainTest.java
src/test/java/com/zksy/szpt/MainTest.java
+32
-272
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
+5
-5
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
011ebb60
...
@@ -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/MainTest.java
View file @
011ebb60
...
@@ -29,8 +29,6 @@ public class MainTest {
...
@@ -29,8 +29,6 @@ public class MainTest {
String
nonce
=
"2"
;
String
nonce
=
"2"
;
String
timestampStr
=
"21"
;
String
timestampStr
=
"21"
;
String
appId
=
"1872576325743943682"
;
String
appId
=
"1872576325743943682"
;
String
appSecret
=
"2"
;
@Resource
@Resource
private
ObjectMapper
objectMapper
;
private
ObjectMapper
objectMapper
;
...
@@ -41,47 +39,18 @@ public class MainTest {
...
@@ -41,47 +39,18 @@ public class MainTest {
/**
/**
* 任务完成情况
* 任务完成情况
*/
*/
//
@Test
@Test
@DisplayName
(
"任务完成情况"
)
@DisplayName
(
"任务完成情况"
)
public
void
xxRwwcqkTest
()
{
public
void
xxRwwcqkTest
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
// String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
appSecret
=
DigestUtil
.
md5Hex
(
appSecret
);
Assertions
.
assertNotNull
(
appId
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
//请求参数
XxRwwcqkDTO
xxRwwcqkDTO
=
new
XxRwwcqkDTO
();
XxRwwcqkDTO
xxRwwcqkDTO
=
new
XxRwwcqkDTO
();
xxRwwcqkDTO
.
setRwid
(
"1234"
);
xxRwwcqkDTO
.
setRwid
(
"1234
5678
"
);
xxRwwcqkDTO
.
setXxyid
(
"12345"
);
xxRwwcqkDTO
.
setXxyid
(
"12345
6785
"
);
xxRwwcqkDTO
.
setShrid
(
"12345"
);
xxRwwcqkDTO
.
setShrid
(
"12345
6785
"
);
xxRwwcqkDTO
.
setWczt
(
"1"
);
xxRwwcqkDTO
.
setWczt
(
"1"
);
xxRwwcqkDTO
.
setBmzt
(
"1"
);
xxRwwcqkDTO
.
setBmzt
(
"1"
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/index/addXxRwwcqk", xxRwwcqkDTO, XxRwwcqkDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/index/updateXxRwwcqk"
,
xxRwwcqkDTO
,
XxRwwcqkDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
xxRwwcqkDTO
);
}
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/index/addXxRwwcqk"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
xxRwwcqkDTO
),
XxRwwcqkDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
/**
/**
...
@@ -90,43 +59,14 @@ public class MainTest {
...
@@ -90,43 +59,14 @@ public class MainTest {
@Test
@Test
@DisplayName
(
"账户信息"
)
@DisplayName
(
"账户信息"
)
public
void
zhxxtest
()
{
public
void
zhxxtest
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey);
//请求参数
//请求参数
XxZhxxDTO
dto
=
new
XxZhxxDTO
();
XxZhxxDTO
dto
=
new
XxZhxxDTO
();
dto
.
setZhid
(
"1234"
);
dto
.
setZhid
(
"1234
5678
"
);
dto
.
setXxyid
(
"11"
);
dto
.
setXxyid
(
"11"
);
dto
.
setZt
(
"2"
);
dto
.
setZt
(
"2"
);
dto
.
setClbz
(
"2"
);
dto
.
setClbz
(
"2"
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxZhxx/add", dto, XxZhxxDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxZhxx/update"
,
dto
,
XxZhxxDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxZhxx/add"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxZhxxDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
/**
/**
...
@@ -135,43 +75,14 @@ public class MainTest {
...
@@ -135,43 +75,14 @@ public class MainTest {
@Test
@Test
@DisplayName
(
"账户积分变更"
)
@DisplayName
(
"账户积分变更"
)
public
void
test1
()
{
public
void
test1
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey);
//请求参数
//请求参数
XxZhjfbgDTO
dto
=
new
XxZhjfbgDTO
();
XxZhjfbgDTO
dto
=
new
XxZhjfbgDTO
();
// dto.setZhid("1234");
// dto.setZhid("1234
5678
");
dto
.
setDhid
(
"1234"
);
dto
.
setDhid
(
"1234
5678
"
);
dto
.
setQbid
(
"2"
);
dto
.
setQbid
(
"2"
);
dto
.
setBgsj
(
new
Date
());
dto
.
setBgsj
(
new
Date
());
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxZhjfbg/add", dto, XxZhjfbgDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxZhjfbg/update"
,
dto
,
XxZhjfbgDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxZhjfbg/add"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxZhjfbgDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
...
@@ -224,46 +135,17 @@ public class MainTest {
...
@@ -224,46 +135,17 @@ public class MainTest {
@Test
@Test
@DisplayName
(
"义警任务"
)
@DisplayName
(
"义警任务"
)
public
void
test4
()
{
public
void
test4
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey);
//请求参数
//请求参数
XxYjrwDTO
dto
=
new
XxYjrwDTO
();
XxYjrwDTO
dto
=
new
XxYjrwDTO
();
// dto.setZhid("1234");
// dto.setZhid("1234
5678
");
dto
.
setRwid
(
"123456"
);
dto
.
setRwid
(
"123456
7856
"
);
dto
.
setRwbt
(
"1"
);
dto
.
setRwbt
(
"1"
);
dto
.
setRwnr
(
"11111"
);
dto
.
setRwnr
(
"11111"
);
dto
.
setGzrs
(
1L
);
dto
.
setGzrs
(
1L
);
dto
.
setSfsh
(
1
);
dto
.
setSfsh
(
1
);
dto
.
setWcrs
(
1L
);
dto
.
setWcrs
(
1L
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxYjrw/add", dto, XxYjrwDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxYjrw/update"
,
dto
,
XxYjrwDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxYjrw/update"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxYjrwDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
/**
/**
...
@@ -272,179 +154,57 @@ public class MainTest {
...
@@ -272,179 +154,57 @@ public class MainTest {
@Test
@Test
@DisplayName
(
"义警队伍代码"
)
@DisplayName
(
"义警队伍代码"
)
public
void
test5
()
{
public
void
test5
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey);
//请求参数
//请求参数
XxYjdwdmDTO
dto
=
new
XxYjdwdmDTO
();
XxYjdwdmDTO
dto
=
new
XxYjdwdmDTO
();
// dto.setZhid("1234");
// dto.setZhid("1234
5678
");
dto
.
setDwlx
(
Integer
.
valueOf
(
1
));
dto
.
setDwlx
(
Integer
.
valueOf
(
1
));
dto
.
setId
(
"1234"
);
dto
.
setId
(
"1234
5678
"
);
dto
.
setMchid
(
"11111"
);
dto
.
setMchid
(
"11111"
);
dto
.
setZt
(
"1"
);
dto
.
setZt
(
"1"
);
dto
.
setYjdwmc
(
"test"
);
dto
.
setYjdwmc
(
"test"
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxYjdwdm/add", dto, XxYjdwdmDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxYjdwdm/update"
,
dto
,
XxYjdwdmDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxYjdwdm/add"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxYjdwdmDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
@Test
@Test
@DisplayName
(
"社会信息员队伍"
)
@DisplayName
(
"社会信息员队伍"
)
public
void
test6
()
{
public
void
test6
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
XxShxxyDwDTO
dto
=
new
XxShxxyDwDTO
();
XxShxxyDwDTO
dto
=
new
XxShxxyDwDTO
();
dto
.
setId
(
"1234"
);
dto
.
setId
(
"12345678"
);
dto
.
setDwdm
(
"1234"
);
dto
.
setDwdm
(
"12345678"
);
dto
.
setShxxyid
(
"1234"
);
dto
.
setShxxyid
(
"12345678"
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxShxxyDw/add", dto, XxShxxyDwDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxShxxyDw/update"
,
dto
,
XxShxxyDwDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxShxxyDw/add"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxShxxyDw
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
@Test
@Test
@DisplayName
(
"社会信息员"
)
@DisplayName
(
"社会信息员"
)
public
void
test7
()
{
public
void
test7
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
XxShxxyDTO
dto
=
new
XxShxxyDTO
();
XxShxxyDTO
dto
=
new
XxShxxyDTO
();
dto
.
setXxyid
(
"1234"
);
dto
.
setXxyid
(
"1234
5678
"
);
dto
.
setZt
(
"1"
);
dto
.
setZt
(
"1"
);
dto
.
setSbfszt
(
"1"
);
dto
.
setSbfszt
(
"1"
);
dto
.
setShrid
(
"1"
);
dto
.
setShrid
(
"1"
);
String
json
=
null
;
// TestHttpUtil.signatureAndRequest("/rest/xxShxxy/add", dto, XxShxxyDTO.class);
try
{
TestHttpUtil
.
signatureAndRequest
(
"/rest/xxShxxy/update"
,
dto
,
XxShxxyDTO
.
class
);
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
json
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名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/xxShxxy/add"
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
XxShxxyDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
@Test
@Test
@DisplayName
(
"删除服务"
)
@DisplayName
(
"删除服务"
)
public
void
testdelete
()
{
public
void
testdelete
()
{
timestampStr
=
String
.
valueOf
(
System
.
currentTimeMillis
()
/
1000
);
nonce
=
UUID
.
randomUUID
().
toString
();
String
secretKey
=
this
.
appStoreService
.
getAppSecretByAppKey
(
appId
);
Assertions
.
assertNotNull
(
secretKey
,
"appId不存在"
);
//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
String
json
=
null
;
List
<
String
>
ids
=
new
ArrayList
<>();
List
<
String
>
ids
=
new
ArrayList
<>();
ids
.
add
(
"1234"
);
ids
.
add
(
"1234
5678
"
);
ids
.
add
(
"12345"
);
ids
.
add
(
"12345
6785
"
);
CommonDelParamDTO
dto
=
new
CommonDelParamDTO
();
CommonDelParamDTO
dto
=
new
CommonDelParamDTO
();
dto
.
setIds
(
ids
);
dto
.
setIds
(
ids
);
try
{
json
=
objectMapper
.
writeValueAsString
(
dto
);
}
catch
(
JsonProcessingException
e
)
{
Assertions
.
fail
(
"json序列化失败"
);
}
//请求体加密
String
json1
=
EncryptUtil
.
getInstance
().
AESEncode
(
json
,
secretKey
);
//签名appId+nonce+timestampStr+aes(body)
String
data
=
String
.
format
(
"%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
json1
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
//请求
WebClient
webClient
=
WebClient
.
builder
()
.
baseUrl
(
"http://localhost:8086"
)
.
defaultHeader
(
"Content-Type"
,
"application/json"
)
.
build
();
// String url="xxShxxyDw/delete";
// String url="xxShxxyDw/delete";
// String url="xxShxxy/delete";
// String url="xxShxxy/delete";
// String url="xxYjdwdm/delete";
// String url="xxYjdwdm/delete";
// String url="xxYjrw/delete";
// String url="xxYjrw/delete";
//
// String url="xxZhjfbg/delete";
// String url="xxZhjfbg/delete";
//
String
url
=
"xxZhxx/delete"
;
String
url
=
"xxZhxx/delete"
;
TestHttpUtil
.
signatureAndRequest
(
"/rest/"
+
url
,
dto
,
CommonDelParamDTO
.
class
);
String
response
=
webClient
.
post
().
uri
(
"/rest/"
+
url
)
.
header
(
SignatureUtil
.
APPID
,
appId
)
.
header
(
SignatureUtil
.
NONCE
,
nonce
)
.
header
(
SignatureUtil
.
TIMESTAMP
,
timestampStr
)
.
header
(
SignatureUtil
.
SIGNATURE
,
generatedSignature
)
.
body
(
Mono
.
just
(
dto
),
CommonDelDTO
.
class
)
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
block
();
System
.
out
.
println
(
response
);
}
}
}
}
src/test/java/com/zksy/szpt/TestAppStore.java
View file @
011ebb60
...
@@ -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 @
011ebb60
...
@@ -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
);
...
@@ -60,8 +61,7 @@ public class TestHttpUtil {
...
@@ -60,8 +61,7 @@ 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
);
...
...
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