添加接口 获取城市矢量边界
This commit is contained in:
parent
f9dfe0cdb4
commit
dd150b1d22
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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请求
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user