81 lines
2.8 KiB
Java
81 lines
2.8 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import cn.hutool.http.HttpGlobalConfig;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections.MapUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @program: wisdomSite
|
|
* @description: 标养室对接接口
|
|
* @author: Mr.Peng
|
|
* @create: 2021-05-24 14:57
|
|
**/
|
|
@Slf4j
|
|
public class StandardDevUtil {
|
|
|
|
//账户
|
|
public static final String loginName = "t210127lekd";
|
|
//密码
|
|
public static final String password = "t210127lekd";
|
|
public static final String url = "http://iot.0531yun.cn/wsjc";
|
|
private static String userId = "";
|
|
|
|
public static String getLoginUserId() {
|
|
Map<String, String> param = new HashMap<>();
|
|
param.put("loginName", loginName);
|
|
param.put("password", password);
|
|
String result = HttpUtil.post(url + "/app/Login", JSONUtil.toJsonStr(param));
|
|
if (StringUtils.isNotEmpty(result)) {
|
|
JSONObject object = JSONObject.parseObject(result);
|
|
String code = String.valueOf(object.get("code").toString());
|
|
if ("1000".equals(code)) {
|
|
Map<String, Object> map = com.zhgd.jeecg.common.util.JSONUtil.readValueToMap(object.get("data").toString());
|
|
return MapUtils.getString(map, "userId");
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static JSONArray getDeviceData(String groupId) {
|
|
if (StringUtils.isEmpty(userId)) {
|
|
userId = getLoginUserId();
|
|
}
|
|
Map<String, Object> param = new HashMap<>();
|
|
param.put("groupId", groupId);
|
|
Map<String, String> headerMap = new HashMap<>();
|
|
headerMap.put("userId", userId);
|
|
String result = get(url + "/app/GetDeviceData", param, headerMap);
|
|
//log.info("result:"+result);
|
|
if (StringUtils.isNotEmpty(result)) {
|
|
log.info("------------获取标样室实时数据结果---------");
|
|
JSONObject object = JSONObject.parseObject(result);
|
|
String code = String.valueOf(object.get("code").toString());
|
|
if ("1000".equals(code)) {
|
|
JSONArray array = object.getJSONArray("data");
|
|
return array;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
public static String get(String urlString, Map<String, Object> paramMap, Map<String, String> headerMap) {
|
|
return HttpRequest.get(urlString).addHeaders(headerMap).form(paramMap).timeout(HttpGlobalConfig.getTimeout()).execute().body();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
//log.info(getLoginUserId());
|
|
//log.info(getDeviceData("").toJSONString());
|
|
|
|
}
|
|
}
|