易微联开放接口获取设备列表信息(java处理)
/*** 判断wifi状态** @param barcode* @return*/@SneakyThrows@Overridepublic Boolean status(String barcode) {//获取coolkit的accessTokenCoolkitATDTO coolkitATDTO = eqmtEquipmentMapper.getCoolkitAT();Strin
·
/**
* 判断wifi状态
*
* @param barcode
* @return
*/
@SneakyThrows
@Override
public Boolean status(String barcode) {
//获取coolkit的accessToken
CoolkitATDTO coolkitATDTO = eqmtEquipmentMapper.getCoolkitAT();
String coolkitAT = coolkitATDTO.getCoolkitAT();
String message = "";
message = "{\"thingList\":[{\"itemType\":1,\"id\":\"" + barcode + "\"}]}";
//创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String responseString = "";
Boolean online = null;
try {
//创建Http Post请求
HttpPost httpPost = new HttpPost("https://cn-apia.coolkit.cn/v2/device/thing");
//创建请求内容
//请求参数
JSONObject jsonObject = JSONObject.parseObject(message);
String messageJson = JSONObject.toJSONString(jsonObject);
StringEntity entity = new StringEntity(messageJson, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
//请求头
httpPost.setHeader("X-CK-Appid", "Zuw4KSY6wdFTUPLnvyBqwfXvLOMzBPvU");
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Authorization", "Bearer " + coolkitAT);
//执行http请求
response = httpClient.execute(httpPost);
responseString = EntityUtils.toString(response.getEntity(), "utf-8");
JSONObject responseJsonObject = JSON.parseObject(responseString);
String dataString = responseJsonObject.getString("data");
JSONObject dataJsonObject = JSON.parseObject(dataString);
String thingListString = dataJsonObject.getString("thingList");
JSONArray thingListStringArray = JSONArray.parseArray(thingListString);
JSONObject thingObject = (JSONObject) thingListStringArray.get(0);
String itemDataString = thingObject.getString("itemData");
JSONObject itemDataJsonObject = JSON.parseObject(itemDataString);
//String itemString = itemDataJsonObject.getString("params");
//JSONObject itemJsonObject = JSON.parseObject(itemString);
// System.out.print(itemDataJsonObject+"ppp"+itemJsonObject.getString("switch"));
online = Boolean.parseBoolean(itemDataJsonObject.getString("online"));
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//online为true表示wifi在线,为false表示wifi离线
return online;
}
java请求易微联开发平台的接口,获取到设备的相关信息
itemDataJsonObject这个就是获取到的返回数据信息,根据自己的项目需要进行使用相关数据。
完整代码获取地址https://download.csdn.net/download/qq_31151123/86936380
更多推荐
已为社区贡献1条内容
所有评论(0)