Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
smartDevices-platform-service
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 d828279e
authored
Mar 05, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]代码整改
1 parent
fade68b4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
75 deletions
src/main/java/cn/com/glsx/modules/service/AccessTokenService.java
src/main/java/cn/com/glsx/modules/service/DeviceService.java
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
src/main/java/cn/com/glsx/modules/service/UserService.java
src/main/java/cn/com/glsx/modules/service/AccessTokenService.java
View file @
d828279
...
@@ -43,7 +43,7 @@ public class AccessTokenService {
...
@@ -43,7 +43,7 @@ public class AccessTokenService {
AccessToken
accessToken
=
accessTokenRedis
.
readCache
(
Constants
.
ACCESSTOKEN_REDISKEY
);
AccessToken
accessToken
=
accessTokenRedis
.
readCache
(
Constants
.
ACCESSTOKEN_REDISKEY
);
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
=
sendRequestService
.
sendRequestGet
(
tokenFlashUrl
+
accessToken
.
getRefresh_token
());
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
OA
(
tokenFlashUrl
+
accessToken
.
getRefresh_token
());
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
AccessToken
token
=
JSONObject
.
parseObject
(
result
,
AccessToken
.
class
);
AccessToken
token
=
JSONObject
.
parseObject
(
result
,
AccessToken
.
class
);
...
@@ -57,7 +57,7 @@ public class AccessTokenService {
...
@@ -57,7 +57,7 @@ public class AccessTokenService {
access_Token
=
accessToken
.
getAccess_token
();
access_Token
=
accessToken
.
getAccess_token
();
}
}
}
else
{
}
else
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getTokenUrl
);
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
OA
(
getTokenUrl
);
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
String
result
=
responseBody
.
getResult
();
String
result
=
responseBody
.
getResult
();
AccessToken
token
=
JSONObject
.
parseObject
(
result
,
AccessToken
.
class
);
AccessToken
token
=
JSONObject
.
parseObject
(
result
,
AccessToken
.
class
);
...
...
src/main/java/cn/com/glsx/modules/service/DeviceService.java
View file @
d828279
...
@@ -35,76 +35,53 @@ public class DeviceService {
...
@@ -35,76 +35,53 @@ public class DeviceService {
@Autowired
@Autowired
private
SendRequestService
sendRequestService
;
private
SendRequestService
sendRequestService
;
@Autowired
private
AccessTokenService
accessTokenService
;
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
public
List
<
DeviceInfo
>
getAllDevicesByUser
(
String
uid
)
{
List
<
DeviceInfo
>
userInfo
=
null
;
List
<
DeviceInfo
>
userInfo
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getAllDevicesByUserUrl
.
replace
(
"{uid}"
,
uid
),
accessToken
);
String
result
=
responseBody
.
getResult
();
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
userInfo
=
JSONObject
.
parseArray
(
result
,
DeviceInfo
.
class
);
String
result
=
responseBody
.
getResult
();
userInfo
=
JSONObject
.
parseArray
(
result
,
DeviceInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦
获取用户设备接口
失败"
);
}
}
return
userInfo
;
return
userInfo
;
}
}
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
public
DeviceInfo
getDevicesById
(
String
device_id
)
{
DeviceInfo
deviceInfo
=
null
;
DeviceInfo
deviceInfo
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getDevicesByIdUrl
.
replace
(
"{device_id}"
,
device_id
),
accessToken
);
String
result
=
responseBody
.
getResult
();
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
deviceInfo
=
JSONObject
.
parseObject
(
result
,
DeviceInfo
.
class
);
String
result
=
responseBody
.
getResult
();
deviceInfo
=
JSONObject
.
parseObject
(
result
,
DeviceInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取设备接口失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦
获取设备接口
失败"
);
}
}
return
deviceInfo
;
return
deviceInfo
;
}
}
public
Function
getFunctionsById
(
String
device_id
)
{
public
Function
getFunctionsById
(
String
device_id
)
{
Function
function
=
null
;
Function
function
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByIdUrl
.
replace
(
"{device_id}"
,
device_id
),
accessToken
);
String
result
=
responseBody
.
getResult
();
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦
获取用户设备接口
失败"
);
}
}
return
function
;
return
function
;
}
}
public
Function
getFunctionsByCat
(
String
category
)
{
public
Function
getFunctionsByCat
(
String
category
)
{
Function
function
=
null
;
Function
function
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getFunctionsByCatUrl
.
replace
(
"{category}"
,
category
),
accessToken
);
String
result
=
responseBody
.
getResult
();
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
String
result
=
responseBody
.
getResult
();
function
=
JSONObject
.
parseObject
(
result
,
Function
.
class
);
}
else
{
log
.
info
(
"调用涂鸦获取用户设备接口失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦
获取用户设备接口
失败"
);
}
}
return
function
;
return
function
;
}
}
}
}
src/main/java/cn/com/glsx/modules/service/SendRequestService.java
View file @
d828279
...
@@ -6,6 +6,8 @@ import cn.com.glsx.modules.utils.HttpUtil;
...
@@ -6,6 +6,8 @@ import cn.com.glsx.modules.utils.HttpUtil;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -26,8 +28,16 @@ public class SendRequestService {
...
@@ -26,8 +28,16 @@ public class SendRequestService {
@Value
(
"${tuya.secret}"
)
@Value
(
"${tuya.secret}"
)
private
String
secret
;
private
String
secret
;
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
accessToken
,
String
requestBody
)
{
@Autowired
private
AccessTokenService
accessTokenService
;
public
ResponseBody
sendRequestPost
(
String
requesturl
,
String
requestBody
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
requesturl
,
JSONObject
.
toJSONString
(
requestBody
),
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendPost
(
requesturl
,
JSONObject
.
toJSONString
(
requestBody
),
headerParams
);
...
@@ -39,8 +49,13 @@ public class SendRequestService {
...
@@ -39,8 +49,13 @@ public class SendRequestService {
return
responseBody
;
return
responseBody
;
}
}
public
ResponseBody
sendRequestGet
(
String
requesturl
,
String
accessToken
)
{
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
log
.
info
(
"获取token失败"
);
return
responseBody
;
}
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
,
accessToken
);
try
{
try
{
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
headerParams
);
JSONObject
jsonObject
=
HttpUtil
.
sendGet
(
requesturl
,
null
,
headerParams
);
...
@@ -52,7 +67,7 @@ public class SendRequestService {
...
@@ -52,7 +67,7 @@ public class SendRequestService {
return
responseBody
;
return
responseBody
;
}
}
public
ResponseBody
sendRequestGet
(
String
requesturl
)
{
public
ResponseBody
sendRequestGet
OA
(
String
requesturl
)
{
ResponseBody
responseBody
=
null
;
ResponseBody
responseBody
=
null
;
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
Map
<
String
,
String
>
headerParams
=
HeaderParamUtils
.
buildHeaderParams
(
client_id
,
secret
);
try
{
try
{
...
...
src/main/java/cn/com/glsx/modules/service/UserService.java
View file @
d828279
...
@@ -26,9 +26,6 @@ public class UserService {
...
@@ -26,9 +26,6 @@ public class UserService {
private
String
getUserInfoUrl
;
private
String
getUserInfoUrl
;
@Autowired
@Autowired
private
AccessTokenService
accessTokenService
;
@Autowired
private
SendRequestService
sendRequestService
;
private
SendRequestService
sendRequestService
;
/**
/**
...
@@ -38,25 +35,19 @@ public class UserService {
...
@@ -38,25 +35,19 @@ public class UserService {
*/
*/
public
String
registerUser
(
UserBo
userBo
)
{
public
String
registerUser
(
UserBo
userBo
)
{
//获取令牌
//获取令牌
String
uid
=
null
;
String
uid
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
registerUserUrl
,
JSONObject
.
toJSONString
(
userBo
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestPost
(
registerUserUrl
,
accessToken
,
JSONObject
.
toJSONString
(
userBo
));
String
result
=
responseBody
.
getResult
();
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
()){
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
String
result
=
responseBody
.
getResult
();
uid
=
jsonObject
.
getString
(
"uid"
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
uid
=
jsonObject
.
getString
(
"uid"
);
}
else
{
log
.
info
(
"调用涂鸦失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦失败"
);
}
}
return
uid
;
return
uid
;
}
}
/**
/**
* 获取用户信息
* 获取用户信息
*
*
...
@@ -64,17 +55,12 @@ public class UserService {
...
@@ -64,17 +55,12 @@ public class UserService {
*/
*/
public
UserInfo
getUserInfo
(
String
id
)
{
public
UserInfo
getUserInfo
(
String
id
)
{
UserInfo
userInfo
=
null
;
UserInfo
userInfo
=
null
;
String
accessToken
=
accessTokenService
.
getAccessToken
();
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
));
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
ResponseBody
responseBody
=
sendRequestService
.
sendRequestGet
(
getUserInfoUrl
.
replace
(
"{uid}"
,
id
),
accessToken
);
String
result
=
responseBody
.
getResult
()
+
""
;
if
(
responseBody
!=
null
&&
responseBody
.
isSuccess
())
{
userInfo
=
JSONObject
.
parseObject
(
result
,
UserInfo
.
class
);
String
result
=
responseBody
.
getResult
()+
""
;
userInfo
=
JSONObject
.
parseObject
(
result
,
UserInfo
.
class
);
}
else
{
log
.
info
(
"调用涂鸦用户信息接口失败"
);
}
}
else
{
}
else
{
log
.
info
(
"调用涂鸦
鉴权
失败"
);
log
.
info
(
"调用涂鸦
用户信息接口
失败"
);
}
}
return
userInfo
;
return
userInfo
;
}
}
...
...
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