2023-02-16 15:28:15 +08:00
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
//账户
|
2023-12-22 18:35:08 +08:00
|
|
|
//public static final String loginName = "t210127lekd";
|
2024-01-03 10:12:32 +08:00
|
|
|
//public static final String loginName = "2023wenshiduceshi";
|
2023-02-16 15:28:15 +08:00
|
|
|
//密码
|
2023-12-22 18:35:08 +08:00
|
|
|
//public static final String password = "t210127lekd";
|
2024-01-03 10:12:32 +08:00
|
|
|
//public static final String password = "2023wenshiduceshi";
|
2023-12-22 18:35:08 +08:00
|
|
|
//public static final String url = "http://iot.0531yun.cn/wsjc";
|
|
|
|
|
public static final String url = "https://www.0531yun.com";
|
2023-02-16 15:28:15 +08:00
|
|
|
private static String userId = "";
|
|
|
|
|
|
2024-01-03 10:12:32 +08:00
|
|
|
public static String getLoginUserId(String jnrzckAccount, String jnrzckPw) {
|
2023-02-16 15:28:15 +08:00
|
|
|
Map<String, String> param = new HashMap<>();
|
2024-01-03 10:12:32 +08:00
|
|
|
param.put("loginName", jnrzckAccount);
|
|
|
|
|
param.put("password", jnrzckPw);
|
2023-12-22 18:35:08 +08:00
|
|
|
String urlString = url + "/app/Login";
|
|
|
|
|
String body = JSONUtil.toJsonStr(param);
|
|
|
|
|
log.info("url:{},body:{}", urlString, body);
|
|
|
|
|
String result = HttpUtil.post(urlString, body);
|
|
|
|
|
log.info("result:{}", result);
|
2023-02-16 15:28:15 +08:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 10:12:32 +08:00
|
|
|
public static JSONArray getDeviceData(String groupId, String jnrzckAccount, String jnrzckPw) {
|
|
|
|
|
userId = getLoginUserId(jnrzckAccount, jnrzckPw);
|
2023-02-16 15:28:15 +08:00
|
|
|
Map<String, Object> param = new HashMap<>();
|
|
|
|
|
param.put("groupId", groupId);
|
|
|
|
|
Map<String, String> headerMap = new HashMap<>();
|
|
|
|
|
headerMap.put("userId", userId);
|
2023-12-22 18:35:08 +08:00
|
|
|
String urlString = url + "/app/GetDeviceData";
|
|
|
|
|
log.info("url:{},param:{},headerMap:{}", urlString, param, headerMap);
|
|
|
|
|
String result = get(urlString, param, headerMap);
|
|
|
|
|
log.info("result:{}", result);
|
2023-02-16 15:28:15 +08:00
|
|
|
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) {
|
|
|
|
|
}
|
|
|
|
|
}
|