Commit c8082499 by tyfanchz

设备订阅修改

1 parent 5af9d758
...@@ -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);
}
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!