diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index c4b8856..fb3c5c8 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -57,6 +57,7 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/api/adm/getCityList").permitAll()//根据省编号获取市列表 .antMatchers(HttpMethod.GET, "/api/adm/getCountyList").permitAll()//根据市编号获取区县列表 .antMatchers(HttpMethod.GET, "/api/adm/getStreetList").permitAll()//根据区县编号获取街道列表 + .antMatchers(HttpMethod.GET, "/queryVectorBoundary").permitAll()//获取城市矢量边界 // 所有其它请求需要身份认证 .anyRequest().authenticated() .and() diff --git a/src/main/java/com/xkrs/controller/VectorBoundaryController.java b/src/main/java/com/xkrs/controller/VectorBoundaryController.java new file mode 100644 index 0000000..9a97aae --- /dev/null +++ b/src/main/java/com/xkrs/controller/VectorBoundaryController.java @@ -0,0 +1,33 @@ +package com.xkrs.controller; + +import com.xkrs.utilsold.HttpClientUtils; +import org.apache.hc.core5.util.TextUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class VectorBoundaryController { + + @GetMapping("/queryVectorBoundary") + public String queryVectorBoundary(@RequestParam(value = "tk", required = false) String tk, + @RequestParam(value = "lon") Double lon, + @RequestParam(value = "lat") Double lat, + @RequestParam(value = "scale") Double scale, + @RequestParam(value = "bgeo", required = false) Boolean bgeo) throws Exception { + String defaultTk = "9cc3e9deb3cf643b6f133717c333d16d"; + Boolean defaultBgeo = true; + String finalTk = (TextUtils.isEmpty(tk)) ? defaultTk : tk; + Boolean finalBgeo = (bgeo == null) ? defaultBgeo : bgeo; + + StringBuilder builder = new StringBuilder("https://service.sdmap.gov.cn/citysearch"); + builder.append("?tk=").append(finalTk); + builder.append("&lon=").append(lon); + builder.append("&lat=").append(lat); + builder.append("&scale=").append(scale); + builder.append("&bgeo=").append(finalBgeo); + String url = builder.toString(); + return HttpClientUtils.sendHttpsGetCustom(url); + } + +} diff --git a/src/main/java/com/xkrs/utilsold/HttpClientUtils.java b/src/main/java/com/xkrs/utilsold/HttpClientUtils.java index dbcdbb6..71b098c 100644 --- a/src/main/java/com/xkrs/utilsold/HttpClientUtils.java +++ b/src/main/java/com/xkrs/utilsold/HttpClientUtils.java @@ -62,6 +62,25 @@ public class HttpClientUtils { return doGet(url, httpClient); } + /** + * 发送https+get请求,绕过证书 + * + * @param url 请求地址 + * @return 返回结果 + * @throws Exception + */ + public static String sendHttpsGetCustom(String url) throws Exception { + SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(), NoopHostnameVerifier.INSTANCE); + CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(scsf).build(); + if (printLog) { + log.info("HGet请求url={}", url); + } + HttpGet httpGet = new HttpGet(url); + httpGet.addHeader("Referer", "http://sdmap.gov.cn/"); + httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"); + return execute(httpClient, httpGet); + } + /** * 发送http+post请求 *