Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-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 c8082499
authored
Apr 27, 2021
by
tyfanchz
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
设备订阅修改
1 parent
5af9d758
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
src/main/java/com/glsx/smart/service/impl/SmartUserDeviceServiceImpl.java
View file @
c808249
...
@@ -179,28 +179,31 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
...
@@ -179,28 +179,31 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
}
}
// 通过用户手机号获取用户 token
// 通过用户手机号获取用户 token
SmartUserRelation
userRelation
=
userRelationMapper
.
selectByPrimaryKey
(
req
.
getUserId
());
SmartUserRelation
userRelation
=
userRelationMapper
.
selectByPrimaryKey
(
req
.
getUserId
());
String
phone
=
userRelation
.
getPhone
();
String
token
=
(
String
)
redisService
.
get
(
userRelation
.
getPhone
()
+
"_aqara"
);
String
token
=
(
String
)
redisService
.
get
(
phone
+
"_aqara"
);
// 查询支持的指令集
// 查询支持的指令集
List
<
String
>
commands
=
productMapper
.
getSupportedCommands
(
req
.
getPlatformProductId
());
List
<
String
>
commands
=
productMapper
.
getSupportedCommands
(
req
.
getPlatformProductId
());
// 请求 url 参数
log
.
info
(
"$$$$ subscribeDevice commands = {}"
,
JSON
.
toJSONString
(
commands
));
Map
<
String
,
Object
>
reqParam
=
new
HashMap
<>();
if
(!
commands
.
isEmpty
())
{
reqParam
.
put
(
"token"
,
token
);
// 指令集不为空才订阅
// 请求 body
// 请求 url 参数
JSONObject
reqData
=
new
JSONObject
();
Map
<
String
,
Object
>
reqParam
=
new
HashMap
<>();
reqData
.
put
(
"did"
,
req
.
getDeviceId
());
reqParam
.
put
(
"token"
,
token
);
reqData
.
put
(
"attrs"
,
commands
);
// 请求 body
JSONObject
reqObj
=
new
JSONObject
();
JSONObject
reqData
=
new
JSONObject
();
reqObj
.
put
(
"data"
,
reqData
);
reqData
.
put
(
"did"
,
req
.
getDeviceId
());
String
rawUrl
=
remoteUrl
+
userDeviceSubscribeApi
;
reqData
.
put
(
"attrs"
,
commands
);
String
url
=
HttpUtils
.
urlWithForm
(
rawUrl
,
reqParam
,
StandardCharsets
.
UTF_8
,
JSONObject
reqObj
=
new
JSONObject
();
true
);
reqObj
.
put
(
"data"
,
reqData
);
log
.
info
(
"$$$$ subscribeDevice url = {}, req = {}"
,
url
,
reqObj
.
toJSONString
());
String
rawUrl
=
remoteUrl
+
userDeviceSubscribeApi
;
String
respJson
=
HttpUtils
.
post
(
url
,
reqObj
.
toJSONString
());
String
url
=
HttpUtils
.
urlWithForm
(
rawUrl
,
reqParam
,
StandardCharsets
.
UTF_8
,
log
.
info
(
"$$$$ subscribeDevice resp = {}"
,
respJson
);
true
);
JSONObject
respObj
=
JSON
.
parseObject
(
respJson
);
log
.
info
(
"$$$$ subscribeDevice url = {}, req = {}"
,
url
,
reqObj
.
toJSONString
());
if
(!
"200"
.
equals
(
respObj
.
getString
(
"code"
)))
{
String
respJson
=
HttpUtils
.
post
(
url
,
reqObj
.
toJSONString
());
throw
BusinessException
.
create
(
ResultEnum
.
DEVICE_SUBSCRIBE_ERROR
);
log
.
info
(
"$$$$ subscribeDevice resp = {}"
,
respJson
);
JSONObject
respObj
=
JSON
.
parseObject
(
respJson
);
if
(!
"200"
.
equals
(
respObj
.
getString
(
"code"
)))
{
throw
BusinessException
.
create
(
ResultEnum
.
DEVICE_SUBSCRIBE_ERROR
);
}
}
}
}
}
}
}
...
...
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