Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
马天浩
jiwei-api
Commits
a9966def
Commit
a9966def
authored
Sep 08, 2020
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[纪委接口] <update> 修改刷新秘钥方式,获取秘钥30s内不重新获取秘钥
parent
94b4ce40
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
6 deletions
+23
-6
Constants.java
src/main/java/com/mth/requestsecret/constant/Constants.java
+5
-1
RequestSecretSchedulerTask.java
...h/requestsecret/scheduler/RequestSecretSchedulerTask.java
+4
-1
RestTemplateService.java
...va/com/mth/requestsecret/service/RestTemplateService.java
+14
-4
No files found.
src/main/java/com/mth/requestsecret/constant/Constants.java
View file @
a9966def
...
...
@@ -9,9 +9,13 @@ public class Constants {
// redis存储请求秘钥key值
//-----------------------------------
/**
* 数据局接口
* 数据局接口
秘钥
*/
public
static
final
String
SJJ_REQUEST_SECRET_PREFIX
=
"sjj.request.secret"
;
/**
* 数据局接口过期时间
*/
public
static
final
String
SJJ_REQUEST_EXPIRE_TIME_PREFIX
=
"sjj.request.expire.time"
;
/**
* 招必得接口
*/
...
...
src/main/java/com/mth/requestsecret/scheduler/RequestSecretSchedulerTask.java
View file @
a9966def
...
...
@@ -105,8 +105,11 @@ public class RequestSecretSchedulerTask implements SchedulingConfigurer {
requestSecretEndTime
=
Long
.
parseLong
(
datas
.
getString
(
"requestSecretEndTime"
));
refreshSecret
=
datas
.
getString
(
"refreshSecret"
);
refreshSecretEndTime
=
Long
.
parseLong
(
datas
.
getString
(
"refreshSecretEndTime"
));
// 保存请求秘钥至redis
// 设置过期时间,30秒内不重新刷新秘钥
String
expireTime
=
String
.
valueOf
(
requestSecretEndTime
-
(
14
*
60
*
1000
+
30
*
1000
));
// redis保存 请求秘钥 和 过期时间
redisUtil
.
set
(
Constants
.
SJJ_REQUEST_SECRET_PREFIX
,
requestSecret
);
redisUtil
.
set
(
Constants
.
SJJ_REQUEST_EXPIRE_TIME_PREFIX
,
expireTime
);
}
}
...
...
src/main/java/com/mth/requestsecret/service/RestTemplateService.java
View file @
a9966def
...
...
@@ -15,11 +15,13 @@ import org.springframework.stereotype.Component;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.time.Instant
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.util.Date
;
import
java.util.Objects
;
import
static
com
.
mth
.
requestsecret
.
constant
.
Constants
.
RESPONSE_CODE_14
;
import
static
com
.
mth
.
requestsecret
.
constant
.
Constants
.
SJJ_REQUEST_SECRET_PREFIX
;
import
static
com
.
mth
.
requestsecret
.
constant
.
Constants
.*;
/**
* @author fyl
...
...
@@ -109,8 +111,16 @@ public class RestTemplateService {
if
(
RESPONSE_CODE_14
.
equals
(
code
)
&&
count
<
2
)
{
threadLocal
.
set
(++
count
);
log
.
info
(
"线程名称:{},重新请求次数:{}"
,
threadName
,
count
);
// 获取秘钥
// redis 中获取过期时间
String
expireTimeStr
=
redisUtil
.
get
(
SJJ_REQUEST_EXPIRE_TIME_PREFIX
);
LocalDateTime
expireTime
=
Instant
.
ofEpochMilli
(
Long
.
parseLong
(
expireTimeStr
)).
atZone
(
ZoneOffset
.
ofHours
(
8
)).
toLocalDateTime
();
LocalDateTime
now
=
LocalDateTime
.
now
();
// 当前时间超过过期时间,重新请求秘钥,否则重新发送请求
if
(
now
.
isAfter
(
expireTime
))
{
log
.
info
(
"redis中过期时间:{},当前时间:{}"
,
expireTime
,
now
);
// 重新获取秘钥
schedulerTask
.
getRequestSecret
();
}
// 重新调用请求
return
commonSendRequest
(
paramMap
,
apiMethod
);
}
...
...
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