| | |
| | | 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; |
| | |
| | | return "fail"; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public String fenceDelete(String gaodeKey, String serviceId, String fenceId) { |
| | | String url = "https://tsapi.amap.com/v1/track/geofence/delete"; |
| | | //电子围栏删除 |
| | | public String fenceDel(String gaodeKey, String sid,String fenceId) { |
| | | String url = "https://tsapi.amap.com/v1/track/geofence/delete?key="+gaodeKey+"&sid="+sid+"&gfids="+fenceId; |
| | | 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); |
| | | //围栏id |
| | | //围栏唯一标识,指定要更新的围栏 |
| | | map.put("sid",sid); |
| | | map.put("gfids",fenceId); |
| | | String param= JSON.toJSONString(map); |
| | | log.info("删除围栏"+param); |
| | | String result = null; |
| | | try { |
| | | result = HttpCurlUtil.sendPostHttp(url, param); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | cn.hutool.json.JSONObject maps = JSONUtil.parseObj(result); |
| | | System.out.println(maps); |
| | | String errcode = maps.get("errcode").toString(); |
| | | if(!"10000".equals(errcode)){ |
| | | return "fail"; |
| | | }else{ |
| | | return maps.toString(); |
| | | } |
| | | } |
| | | @Override |
| | | public String fenceDelete(String gaodeKey, String serviceId, String fenceId) { |
| | | String url = "https://tsapi.amap.com/v1/track/geofence/delete?key="+gaodeKey+"&sid="+serviceId+"&gfids="+fenceId; |
| | | HttpPost httpPost = new HttpPost(url); |
| | | Map<String,String> map = new HashMap<>(); |
| | | map.put("key",gaodeKey); |
| | | map.put("sid",serviceId); |
| | | map.put("gfids",fenceId); |
| | | String param= JSON.toJSONString(map); |
| | | String result = null; |
| | | try { |
| | | result = HttpCurlUtil.sendPostHttp(url, param); |
| | |
| | | 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 gfidsJson = JSONUtil.parseObj(dataStr); |
| | | String gfidsStr = gfidsJson.get("gfids").toString(); |
| | | return gfidsStr; |
| | | }else{ |
| | | System.out.println(maps); |
| | | String errcode = maps.get("errcode").toString(); |
| | | if(!"10000".equals(errcode)){ |
| | | return "fail"; |
| | | }else{ |
| | | return maps.toString(); |
| | | } |
| | | } |
| | | |
| | |
| | | String dataStr = maps.get("data").toString(); |
| | | cn.hutool.json.JSONObject dataResults = JSONUtil.parseObj(dataStr); |
| | | String resultsStr = dataResults.get("results").toString(); |
| | | cn.hutool.json.JSONObject resultsStrJson = JSONUtil.parseObj(resultsStr); |
| | | String in = resultsStrJson.get("in").toString(); |
| | | return in; |
| | | 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); |
| | | } |
| | | } |