package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
@Autowired
private RestTemplate restTemplate;
public String callRemotePostService(String outTransId, String tm) {
System.out.println("支付订单:" + outTransId + "查找月份:" + tm);
String url = "https://yy.yb";
// 设置Cookie
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.COOKIE, "JSESSIONID=3c");
String requestBody = "{\"startDate\":\"2024"+tm+"01\",\"endDate\":\"2024"+tm+"31\",\"outTransId\":"+outTransId+",\"pageNum\":1,\"pageSize\":10}";
HttpEntity<Object> entity = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
return response.getBody();
}
String result = callRemotePostService("4306021991111", "11");
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Map<String, ArrayList<Map>>> user = objectMapper.readValue(result, Map.class);
if (user.get("data").get("list").size() > 0) {
Map<String, String> item = user.get("data").get("list").get(0);
System.out.println("车牌号:" + item.get("deviceNo"));
}