Commit c8082499 by tyfanchz

设备订阅修改

1 parent 5af9d758
......@@ -179,28 +179,31 @@ public class SmartUserDeviceServiceImpl extends BaseService implements SmartUser
}
// 通过用户手机号获取用户 token
SmartUserRelation userRelation = userRelationMapper.selectByPrimaryKey(req.getUserId());
String phone = userRelation.getPhone();
String token = (String) redisService.get(phone + "_aqara");
String token = (String) redisService.get(userRelation.getPhone() + "_aqara");
// 查询支持的指令集
List<String> commands = productMapper.getSupportedCommands(req.getPlatformProductId());
// 请求 url 参数
Map<String, Object> reqParam = new HashMap<>();
reqParam.put("token", token);
// 请求 body
JSONObject reqData = new JSONObject();
reqData.put("did", req.getDeviceId());
reqData.put("attrs", commands);
JSONObject reqObj = new JSONObject();
reqObj.put("data", reqData);
String rawUrl = remoteUrl + userDeviceSubscribeApi;
String url = HttpUtils.urlWithForm(rawUrl, reqParam, StandardCharsets.UTF_8,
true);
log.info("$$$$ subscribeDevice url = {}, req = {}", url, reqObj.toJSONString());
String respJson = HttpUtils.post(url, reqObj.toJSONString());
log.info("$$$$ subscribeDevice resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson);
if (!"200".equals(respObj.getString("code"))) {
throw BusinessException.create(ResultEnum.DEVICE_SUBSCRIBE_ERROR);
log.info("$$$$ subscribeDevice commands = {}", JSON.toJSONString(commands));
if (!commands.isEmpty()) {
// 指令集不为空才订阅
// 请求 url 参数
Map<String, Object> reqParam = new HashMap<>();
reqParam.put("token", token);
// 请求 body
JSONObject reqData = new JSONObject();
reqData.put("did", req.getDeviceId());
reqData.put("attrs", commands);
JSONObject reqObj = new JSONObject();
reqObj.put("data", reqData);
String rawUrl = remoteUrl + userDeviceSubscribeApi;
String url = HttpUtils.urlWithForm(rawUrl, reqParam, StandardCharsets.UTF_8,
true);
log.info("$$$$ subscribeDevice url = {}, req = {}", url, reqObj.toJSONString());
String respJson = HttpUtils.post(url, reqObj.toJSONString());
log.info("$$$$ subscribeDevice resp = {}", respJson);
JSONObject respObj = JSON.parseObject(respJson);
if (!"200".equals(respObj.getString("code"))) {
throw BusinessException.create(ResultEnum.DEVICE_SUBSCRIBE_ERROR);
}
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!