RemoteDeviceService.java
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.model.param.TrackInfoBo;
import cn.com.glsx.admin.modules.utils.GopUtil;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.TreeMap;
@Slf4j
@Service
public class RemoteDeviceService {
/**
* 调用e盾标准接口获取设备信息
*
* @param sn
*/
public TrackInfoBo getDeviceBySn(String sn) {
String url = PropertiesUtils.getProperty("edun.otsi.url") + "/api/device/getInfoBySn";
String appKet = PropertiesUtils.getProperty("edun.otsi.appKet");
String appSecret = PropertiesUtils.getProperty("edun.otsi.appSecret");
TreeMap<String, Object> tparams = new TreeMap<>();
tparams.put("appKey", appKet);
tparams.put("sn", sn);
//加密得到sign
String sign = GopUtil.sign(tparams, appSecret);
tparams.put("sign", sign);
String result = HttpUtils.get(url, tparams);
JSONObject resultObj = JSONObject.parseObject(result);
if (resultObj == null) {
log.info("remote getInfoBysn result is null");
return null;
}
String returnCode = resultObj.getString("returnCode");
String message = resultObj.getString("message");
if (StringUtils.isBlank(returnCode) || !"0".equals(returnCode)) {
log.info("remote getInfoBysn fail! returnCode:" + returnCode + "; message:" + message);
return null;
}
String data = resultObj.getString("data");
if (StringUtils.isBlank(data)) {
return null;
}
TrackInfoBo trackInfoBo = JSONObject.parseObject(data, TrackInfoBo.class);
return trackInfoBo;
}
/**
* 调用e盾标准接口获取设备型号
*
* @param sn 设备号
*/
public String getDeviceClassifyNameBysn(String sn) {
String url = PropertiesUtils.getProperty("edun.otsi.url") + "/api/device/getDeviceClassifyNameBysn";
String appKet = PropertiesUtils.getProperty("edun.otsi.appKet");
String appSecret = PropertiesUtils.getProperty("edun.otsi.appSecret");
TreeMap<String, Object> tparams = new TreeMap<>();
tparams.put("appKey", appKet);
tparams.put("sn", sn);
//加密得到sign
String sign = GopUtil.sign(tparams, appSecret);
tparams.put("sign", sign);
JSONObject resultObj = new JSONObject();
try {
String result = HttpUtils.get(url, tparams);
log.info("getDeviceClassifyNameBysn====result===" + result);
resultObj = JSONObject.parseObject(result);
} catch (Exception e) {
log.info("getDeviceClassifyNameBysn exception===" + e.getMessage(), e);
}
if (resultObj == null) {
log.info("remote getInfoBysn result is null");
return null;
}
String returnCode = resultObj.getString("returnCode");
String message = resultObj.getString("message");
if (StringUtils.isBlank(returnCode) || !"0".equals(returnCode)) {
log.info("remote getInfoBysn fail! returnCode:" + returnCode + "; message:" + message);
return null;
}
String deviceClassifyName = resultObj.getString("data");
if (StringUtils.isBlank(deviceClassifyName)) {
return null;
}
return deviceClassifyName;
}
}