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
b99950dd
Commit
b99950dd
authored
Jan 13, 2025
by
夏敏伟
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://192.168.168.218/wcyuee/szpt
parents
1fb77901
e9665a0b
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
15 deletions
+54
-15
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
...ava/com/zksy/szpt/filter/SignatureVerificationFilter.java
+4
-3
src/main/java/com/zksy/szpt/util/EncryptUtil.java
src/main/java/com/zksy/szpt/util/EncryptUtil.java
+24
-2
src/main/java/com/zksy/szpt/util/SignatureUtil.java
src/main/java/com/zksy/szpt/util/SignatureUtil.java
+1
-1
src/main/resources/application-prod.yml
src/main/resources/application-prod.yml
+13
-0
src/test/java/com/zksy/szpt/TestAppStore.java
src/test/java/com/zksy/szpt/TestAppStore.java
+9
-6
src/test/java/com/zksy/szpt/TestHttpUtil.java
src/test/java/com/zksy/szpt/TestHttpUtil.java
+3
-3
No files found.
src/main/java/com/zksy/szpt/filter/SignatureVerificationFilter.java
View file @
b99950dd
...
...
@@ -116,8 +116,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
// 校验appId
AppStore
appStore
=
this
.
appStoreService
.
getAppSecretInfo
(
appId
);
String
appSecret
=
appStore
.
getAppSecret
();
if
(!
StringUtils
.
hasText
(
appSecret
))
{
if
(
appStore
==
null
||
appStore
.
getAppSecret
()
==
null
)
{
this
.
write
(
response
,
"appId无效:"
+
appId
);
return
false
;
}
...
...
@@ -134,10 +133,12 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
body
=
objectMapper
.
writeValueAsString
(
objectMap
);
logger
.
info
(
"请求参数appId: {}, nonce: {}, timestampStr: {}, 原始body: {}, deptCode: {}"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
String
appSecret
=
appStore
.
getAppSecret
();
body
=
EncryptUtil
.
getInstance
().
AESEncode
(
body
,
appSecret
);
// logger.info("appSecret
{}加密后body: {}", appSecret,body);
logger
.
info
(
"appSecret:
{}加密后body: {}"
,
appSecret
,
body
);
// 校验签名appId+nonce+timestampStr+aes(body,secret)+detCode
String
data
=
String
.
format
(
"%s%s%s%s%s"
,
appId
,
nonce
,
timestampStr
,
body
,
deptCode
);
logger
.
info
(
"待签名数据:{}"
,
data
);
String
generatedSignature
=
DigestUtil
.
md5Hex
(
data
);
if
(!
generatedSignature
.
equals
(
sign
))
{
logger
.
warn
(
"签名有误,generatedSignature:{},sign:{},appId:{},nonce:{},timestampStr:{},deptCode:{}"
,
generatedSignature
,
sign
,
appId
,
nonce
,
timestampStr
,
deptCode
);
...
...
src/main/java/com/zksy/szpt/util/EncryptUtil.java
View file @
b99950dd
...
...
@@ -5,6 +5,7 @@ import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import
javax.crypto.Cipher
;
import
javax.crypto.KeyGenerator
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.IvParameterSpec
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
import
java.security.MessageDigest
;
...
...
@@ -135,13 +136,34 @@ public class EncryptUtil {
return
keyGeneratorES
(
res
,
DES
,
key
,
keySizeDES
,
false
);
}
/**
* 使用AES加密算法经行加密(可逆)
*
* @param data 需要加密的密文
* @param password 秘钥
*/
public
String
AESEncode
(
String
data
,
String
password
)
{
byte
[]
key
=
password
.
getBytes
();
//16字节密钥
byte
[]
iv
=
"1234567890123456"
.
getBytes
();
//iv
SecretKey
secretKey
=
new
SecretKeySpec
(
key
,
"AES"
);
try
{
IvParameterSpec
ivSpec
=
new
IvParameterSpec
(
iv
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/CBC/PKCS5Padding"
);
//加密算法/模式/填充方式
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKey
,
ivSpec
);
byte
[]
encrypted
=
cipher
.
doFinal
(
data
.
getBytes
());
//密文字节数组
return
Base64
.
encode
(
encrypted
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
/**
* 使用AES加密算法经行加密(可逆)
*
* @param res 需要加密的密文
* @param key 秘钥
*/
public
String
AESEncode
(
String
res
,
String
key
)
{
public
String
AESEncode
1
(
String
res
,
String
key
)
{
return
keyGeneratorES
(
res
,
AES
,
key
,
keySizeAES
,
true
);
}
...
...
src/main/java/com/zksy/szpt/util/SignatureUtil.java
View file @
b99950dd
...
...
@@ -5,5 +5,5 @@ public class SignatureUtil {
public
static
String
TIMESTAMP
=
"x-szpt-timestamp"
;
public
static
String
NONCE
=
"x-szpt-nonce"
;
public
static
String
APPID
=
"x-szpt-appid"
;
public
static
String
DEPT_CODE
=
"x-szpt-dept
_
code"
;
public
static
String
DEPT_CODE
=
"x-szpt-dept
-
code"
;
}
src/main/resources/application-prod.yml
0 → 100644
View file @
b99950dd
spring
:
datasource
:
url
:
jdbc:mysql://192.168.168.110:3306/szpt?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
username
:
root
password
:
123456
driver-class-name
:
com.mysql.cj.jdbc.Driver
type
:
com.alibaba.druid.pool.DruidDataSource
redis
:
database
:
0
port
:
6379
password
:
1qaz2wsx
timeout
:
1000
host
:
192.168.168.110
\ No newline at end of file
src/test/java/com/zksy/szpt/TestAppStore.java
View file @
b99950dd
...
...
@@ -15,13 +15,16 @@ public class TestAppStore {
@Test
@DisplayName
(
"新增AppId"
)
public
void
addAppId
()
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
AppStoreDTO
appStoreDTO
=
new
AppStoreDTO
();
appStoreDTO
.
setAppKey
(
"scale"
);
appStoreDTO
.
setAppSecret
(
DigestUtil
.
md5Hex
(
"scale"
));
appStoreDTO
.
setDeptCode
(
"3302020201
"
);
appStoreDTO
.
setDeptCode
(
"330102
"
);
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);
}
...
...
src/test/java/com/zksy/szpt/TestHttpUtil.java
View file @
b99950dd
...
...
@@ -14,9 +14,9 @@ public class TestHttpUtil {
private
static
final
org
.
slf4j
.
Logger
log
=
org
.
slf4j
.
LoggerFactory
.
getLogger
(
TestHttpUtil
.
class
);
static
String
nonce
=
"2"
;
static
String
timestampStr
=
"21"
;
static
String
appId
=
"
scale
"
;
static
String
appSecret
=
DigestUtil
.
md5Hex
(
"
scale
"
);;
static
String
deptCode
=
"330
2020201
"
;
static
String
appId
=
"
1872576325743943682
"
;
static
String
appSecret
=
DigestUtil
.
md5Hex
(
"
2
"
);;
static
String
deptCode
=
"330
102
"
;
private
static
final
ObjectMapper
objectMapper
=
new
ObjectMapper
();
...
...
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