Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-rest-admin-job-archetype
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f3898943
authored
May 17, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码规范
1 parent
6fd86499
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
glsx-rest-admin-job/src/main/java/cn/com/glsx/smarttask/config/TuyaConfig.java
glsx-rest-admin-job/src/main/java/cn/com/glsx/smarttask/modules/job/GetTokenJob.java
glsx-rest-admin-job/src/main/java/cn/com/glsx/smarttask/config/TuyaConfig.java
0 → 100644
View file @
f389894
package
cn
.
com
.
glsx
.
smarttask
.
config
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author zhouhaibao
* @date 2021/5/17 13:49
*/
@Data
@Configuration
public
class
TuyaConfig
{
@Value
(
"${tuya.tokenFlashUrl}"
)
private
String
tokenFlashUrl
;
@Value
(
"${tuya.getTokenUrl}"
)
private
String
getTokenUrl
;
@Value
(
"${tuya.client_id}"
)
private
String
client_id
;
@Value
(
"${tuya.secret}"
)
private
String
secret
;
}
glsx-rest-admin-job/src/main/java/cn/com/glsx/smarttask/modules/job/GetTokenJob.java
View file @
f389894
package
cn
.
com
.
glsx
.
smarttask
.
modules
.
job
;
package
cn
.
com
.
glsx
.
smarttask
.
modules
.
job
;
import
cn.com.glsx.smarttask.config.TuyaConfig
;
import
cn.com.glsx.smarttask.modules.model.param.AccessToken
;
import
cn.com.glsx.smarttask.modules.model.param.AccessToken
;
import
cn.com.glsx.smarttask.common.contants.Constants
;
import
cn.com.glsx.smarttask.common.contants.Constants
;
import
cn.com.glsx.smarttask.modules.model.ResponseBody
;
import
cn.com.glsx.smarttask.modules.model.ResponseBody
;
...
@@ -13,7 +14,6 @@ import com.dangdang.ddframe.job.api.simple.SimpleJob;
...
@@ -13,7 +14,6 @@ import com.dangdang.ddframe.job.api.simple.SimpleJob;
import
com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob
;
import
com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -31,17 +31,8 @@ public class GetTokenJob implements SimpleJob {
...
@@ -31,17 +31,8 @@ public class GetTokenJob implements SimpleJob {
@Autowired
@Autowired
private
AccessTokenRedis
accessTokenRedis
;
private
AccessTokenRedis
accessTokenRedis
;
@Value
(
"${tuya.tokenFlashUrl}"
)
@Autowired
private
String
tokenFlashUrl
;
private
TuyaConfig
tuyaConfig
;
@Value
(
"${tuya.getTokenUrl}"
)
private
String
getTokenUrl
;
@Value
(
"${tuya.client_id}"
)
private
String
client_id
;
@Value
(
"${tuya.secret}"
)
private
String
secret
;
@Override
@Override
public
void
execute
(
ShardingContext
shardingContext
)
{
public
void
execute
(
ShardingContext
shardingContext
)
{
...
@@ -49,7 +40,7 @@ public class GetTokenJob implements SimpleJob {
...
@@ -49,7 +40,7 @@ public class GetTokenJob implements SimpleJob {
log
.
info
(
"redis查询出{}"
,
accessToken
);
log
.
info
(
"redis查询出{}"
,
accessToken
);
if
(
null
!=
accessToken
)
{
if
(
null
!=
accessToken
)
{
if
((
System
.
currentTimeMillis
()-
accessToken
.
getExpire_time
())
>=
1000
*
60
*
60
*
2
)
{
if
((
System
.
currentTimeMillis
()-
accessToken
.
getExpire_time
())
>=
1000
*
60
*
60
*
2
)
{
ResponseBody
responseBody
=
sendRequestGetOA
(
t
okenFlashUrl
+
accessToken
.
getRefresh_token
());
ResponseBody
responseBody
=
sendRequestGetOA
(
t
uyaConfig
.
getTokenFlashUrl
()
+
accessToken
.
getRefresh_token
());
log
.
info
(
"调用刷新接口{}"
,
responseBody
);
log
.
info
(
"调用刷新接口{}"
,
responseBody
);
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
...
@@ -57,11 +48,11 @@ public class GetTokenJob implements SimpleJob {
...
@@ -57,11 +48,11 @@ public class GetTokenJob implements SimpleJob {
token
.
setExpire_time
(
System
.
currentTimeMillis
());
token
.
setExpire_time
(
System
.
currentTimeMillis
());
accessTokenRedis
.
add
(
Constants
.
ACCESSTOKEN_REDISKEY
,
token
);
accessTokenRedis
.
add
(
Constants
.
ACCESSTOKEN_REDISKEY
,
token
);
}
else
{
}
else
{
log
.
info
(
"调用刷新令牌接口异常
"
);
log
.
info
(
"调用刷新令牌接口异常
,错误信息为{}"
,
responseBody
.
getMessage
()
);
}
}
}
}
}
else
{
}
else
{
ResponseBody
responseBody
=
sendRequestGetOA
(
getTokenUrl
);
ResponseBody
responseBody
=
sendRequestGetOA
(
tuyaConfig
.
getGetTokenUrl
()
);
log
.
info
(
"请求body{}"
,
responseBody
);
log
.
info
(
"请求body{}"
,
responseBody
);
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
...
@@ -69,14 +60,14 @@ public class GetTokenJob implements SimpleJob {
...
@@ -69,14 +60,14 @@ public class GetTokenJob implements SimpleJob {
token
.
setExpire_time
(
System
.
currentTimeMillis
());
token
.
setExpire_time
(
System
.
currentTimeMillis
());
accessTokenRedis
.
add
(
Constants
.
ACCESSTOKEN_REDISKEY
,
token
);
accessTokenRedis
.
add
(
Constants
.
ACCESSTOKEN_REDISKEY
,
token
);
}
else
{
}
else
{
log
.
info
(
"调用获取accesstoken接口异常
"
);
log
.
info
(
"调用获取accesstoken接口异常
,错误信息为{}"
,
responseBody
.
getMessage
()
);
}
}
}
}
}
}
public
ResponseBody
sendRequestGetOA
(
String
requesturl
)
{
public
ResponseBody
sendRequestGetOA
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
tuyaConfig
.
getClient_id
(),
tuyaConfig
.
getClient_id
()
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
headerParams
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
responseBody
=
JSON
.
toJavaObject
(
jsonObject
,
ResponseBody
.
class
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment