package com.stylefeng.guns.modular.system.utils.PortUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.stylefeng.guns.core.common.exception.BizExceptionEnum; import com.stylefeng.guns.core.exception.GunsException; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.system.warpper.TerminaleDataWarpper; import java.io.IOException; public class LBCTStrategy implements WharfStrategy { private static final String url = "https://www.lbct.com/CargoSearch/GetMultiCargoSearchJson"; // public static void main(String[] args) throws IOException { // // // 假设您有一个JSON字符串 // String jsonString = "{\"field1\":\"value1\",\"nestedObject\":{\"field2\":\"value2\"}}"; // //// 创建ObjectMapper对象 // ObjectMapper objectMapper = new ObjectMapper(); // //// 将JSON字符串解析为JsonNode对象 // JsonNode jsonNode = objectMapper.readTree(jsonString); // //// 获取嵌套对象中的字段值 // String field2Value = jsonNode.get("nestedObject").get("field2").asText(); // // System.out.println(field2Value); // // // } public static void main(String[] args) { String us = url+ "?timestamp="+System.currentTimeMillis()+"&listOfSearchId="+"GCXU5491260"; HttpResponse execute = HttpRequest.get(us).header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36") .header("cookie", "_ga=GA1.2.1226281326.1675309614; _gid=GA1.2.1467106222.1675309614; _ga=GA1.4.1226281326.1675309614; _gid=GA1.4.1467106222.1675309614; AWSALB=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl; AWSALBCORS=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl") .header("path", "?timestamp=" + System.currentTimeMillis() + "&listOfSearchId=" + "GCXU5491260") .execute(); String body = execute.body(); System.out.println(body); } @Override public TerminaleDataWarpper executeLogic(String... params) { String enums = ""; if (params.length == 0) { throw new GunsException(BizExceptionEnum.REQUEST_EMPTY_ERROR); } else { enums = params[0]; } String us = url+ "?timestamp="+System.currentTimeMillis()+"&listOfSearchId="+enums; HttpResponse execute = HttpRequest.get(us).header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36") .header("cookie", "_ga=GA1.2.1226281326.1675309614; _gid=GA1.2.1467106222.1675309614; _ga=GA1.4.1226281326.1675309614; _gid=GA1.4.1467106222.1675309614; AWSALB=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl; AWSALBCORS=1bWqINVI+LJP87FTEXfEw1Ob1nkbr+I4baSbUGUmu5+/LdiqL9ic04Nj7F0Vz3rvharAG7a8dVe3MX6YMNEbUINVr++CCv/UBw6JeCRS0PcbRLxK7wVHb1lPT8Jl") .header("path", "?timestamp=" + System.currentTimeMillis() + "&listOfSearchId=" + enums) .execute(); String body = execute.body(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonArray = null; TerminaleDataWarpper warpper = new TerminaleDataWarpper(); if (ToolUtil.isEmpty(body)){ return warpper; } try { jsonArray = objectMapper.readTree(body); JsonNode jsonNode = jsonArray.get(0); String appointmentDateTimeLocal = jsonNode.get("gateAppt").asText(); JSONObject jsonObject = JSONObject.parseObject(appointmentDateTimeLocal); Object o = jsonObject.get("IsTMF"); if (o.equals("true")){ warpper.setPierpass("hold"); } Object location = jsonObject.get("location"); if ("GROUNDED".equals(location)){ warpper.setClosedArea(location.toString()); } Object lfd = jsonObject.get("freeTimeExpiration"); if (ToolUtil.isNotEmpty(lfd)){ warpper.setLfd(lfd.toString()); } Object available = jsonObject.get("available"); if (ToolUtil.isNotEmpty(available)){ warpper.setAvailability(available.toString()); } ObjectMapper insMapp = new ObjectMapper(); JsonNode gateAppt1 = insMapp.readTree(jsonObject.get("gateAppt").toString()); String gkey = gateAppt1.get("Gkey").asText(); if (ToolUtil.isNotEmpty(gkey)){ warpper.setAppointmentNumber(gkey); } Object listOfFlag = jsonNode.get(0).get("listOfFlag"); Gson gson = new Gson(); JsonArray jsonElements = gson.fromJson(listOfFlag.toString(), JsonArray.class); for (JsonElement jsonElement : jsonElements) { String holdName = jsonElement.getAsJsonObject().get("holdName").getAsString(); String type = jsonElement.getAsJsonObject().get("type").getAsString(); switch (holdName){ case "CTF_CONTAINER_HOLD": warpper.setCtf(type); break; case "CUSTOMS_DEFAULT_HOLD": warpper.setCustomHold(type); break; case "FREIGHT_BL_HOLD": warpper.setLineHold(type); break; } } } catch (IOException e) { throw new RuntimeException(e); } return warpper; } }