| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson.parser.Feature; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.conn.ssl.NoopHostnameVerifier; |
| | | import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.*; |
| | | import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.TrustManagerFactory; |
| | | import java.security.KeyStore; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | |
| | | return null; |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public HsybGetFuturePo sendRequestToHsyb(String url, String urlParam) { |
| | | // 获取环境 |
| | | String activeProfile = SpringContextUtil.getActiveProfile(); |
| | |
| | | } |
| | | url = url + urlParam; |
| | | log.info("洪水预报请求地址:{}", url); |
| | | |
| | | // 创建一个信任所有证书的 TrustManager |
| | | TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
| | | trustManagerFactory.init((KeyStore) null); |
| | | TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); |
| | | |
| | | // 创建一个不验证主机名的 SSLContext |
| | | SSLContext sslContext = SSLContext.getInstance("TLS"); |
| | | sslContext.init(null, trustManagers, new java.security.SecureRandom()); |
| | | |
| | | // 创建一个不验证主机名的 SSLConnectionSocketFactory |
| | | SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); |
| | | |
| | | // 创建 HttpClient |
| | | CloseableHttpClient httpClient = HttpClients.custom() |
| | | .setSSLSocketFactory(sslsf) |
| | | .build(); |
| | | |
| | | // 创建 HttpComponentsClientHttpRequestFactory 并设置 HttpClient |
| | | HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); |
| | | requestFactory.setHttpClient(httpClient); |
| | | |
| | | // 创建 RestTemplate 并设置请求工厂 |
| | | RestTemplate restTemplate = new RestTemplate(requestFactory); |
| | | |
| | | //设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Authorization", AUTHORIZATION); |
| | | //封装请求头 |
| | | HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<MultiValueMap<String, Object>>(headers); |
| | | HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(headers); |
| | | |
| | | try { |
| | | ResponseEntity<HsybGetFuturePo> exchange = restTemplate.exchange(url, HttpMethod.GET, formEntity, HsybGetFuturePo.class); |
| | |
| | | * "resId": "42092250024" |
| | | * }, |
| | | */ |
| | | if (list.size() == 0) { |
| | | if (null == list || list.size() == 0) { |
| | | return null; |
| | | } |
| | | |