RemoteDeviceService.java 1.94 KB
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;
    }
}