xiaoyong931011
2022-09-16 7f2d3e9bcb89311a5cbfaa617fde71ea412f9bc3
src/main/java/cc/mrbird/febs/mall/service/impl/IMallElectronicFenceServiceImpl.java
@@ -4,6 +4,8 @@
import cc.mrbird.febs.mall.entity.MallElectronicFence;
import cc.mrbird.febs.mall.mapper.MallElectronicFenceMapper;
import cc.mrbird.febs.mall.service.IMallElectronicFenceService;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -241,4 +243,56 @@
            return "fail";
        }
    }
    @Override
    public String fenceToLocation(String gaodeKey, String serviceId, String locationLonglat, String fenceId) {
        String url = "https://tsapi.amap.com/v1/track/geofence/status/location";
        HttpPost httpPost = new HttpPost(url);
        Map<String,String> map = new HashMap<>();
        //高德Key
        //用户在高德地图官网申请Web服务API类型Key
        map.put("key",gaodeKey);
        //服务唯一编号
        //sid为猎鹰service唯一编号
        map.put("sid",serviceId);
        //指定坐标
        //格式:x,y
        map.put("location",locationLonglat);
        //围栏的唯一标识
        //支持一次传入多个,以","分割;
        //单次最多支持100个,如超出将只截取前100个作为输入。
        map.put("gfids",fenceId);
        log.info("查询指定坐标与围栏关系"+JSON.toJSONString(map));
        String result = null;
        try {
            result = HttpCurlUtil.sendGetHttp(url, map);
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("查询指定坐标与围栏关系"+result);
        cn.hutool.json.JSONObject maps = JSONUtil.parseObj(result);
        String errCode = maps.get("errcode").toString();
        if("10000".equals(errCode)){
            String dataStr = maps.get("data").toString();
            cn.hutool.json.JSONObject dataResults = JSONUtil.parseObj(dataStr);
            String resultsStr = dataResults.get("results").toString();
            return resultsStr;
        }else{
            return "fail";
        }
    }
    public static void main(String[] args) {
        String result = "{\"data\":{\"count\":1,\"results\":[{\"gfid\":800899,\"gfname\":\"87053658_fence\",\"in\":0}]},\"errcode\":10000,\"errdetail\":null,\"errmsg\":\"OK\"}";
        cn.hutool.json.JSONObject maps = JSONUtil.parseObj(result);
        String dataStr = maps.get("data").toString();
        cn.hutool.json.JSONObject dataResults = JSONUtil.parseObj(dataStr);
        String resultsStr = dataResults.get("results").toString();
        JSONArray jsonArray = JSONUtil.parseArray(resultsStr);
        System.out.print(jsonArray);
        Object o = jsonArray.get(0);
        JSONObject jsonObject1 = JSONUtil.parseObj(jsonArray.get(0));
        String in = jsonObject1.get("in").toString();
        System.out.print(in);
    }
}