RemoteDeviceService.java
1.94 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
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.apache.logging.log4j.util.PropertiesUtil;
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;
}
}