From fbf16fab0eeaebc4f5ea0cb36108047582b4a713 Mon Sep 17 00:00:00 2001 From: "kuang.yifei@iwhalecloud.com" Date: Wed, 20 Jul 2022 14:32:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BE=E5=BA=A6=E5=9C=B0=E5=9B=BEapi?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=BB=8F=E7=BA=AC=E5=BA=A6=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9C=B0=E7=90=86=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/tool/BaiduController.java | 36 +++++++++++++++++++ ghy-admin/src/main/resources/application.yaml | 5 +++ .../com/ghy/common/config/BaiduConfig.java | 32 +++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 ghy-admin/src/main/java/com/ghy/web/controller/tool/BaiduController.java create mode 100644 ghy-common/src/main/java/com/ghy/common/config/BaiduConfig.java diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/tool/BaiduController.java b/ghy-admin/src/main/java/com/ghy/web/controller/tool/BaiduController.java new file mode 100644 index 00000000..11aea73f --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/controller/tool/BaiduController.java @@ -0,0 +1,36 @@ +package com.ghy.web.controller.tool; + + +import com.ghy.common.config.BaiduConfig; +import com.ghy.common.core.controller.BaseController; +import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.utils.ExceptionUtil; +import com.ghy.common.utils.http.HttpUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/tool/baidu") +public class BaiduController extends BaseController { + + @Autowired + private BaiduConfig baiduConfig; + + @PostMapping("/getLocation") + @ResponseBody + public AjaxResult getLocationByLot(String location){ + try { + String url = baiduConfig.getUrl().replace("#AK#", baiduConfig.getAk()) + location; + String result = HttpUtils.sendGet(url); + return AjaxResult.success(result); + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } + +} diff --git a/ghy-admin/src/main/resources/application.yaml b/ghy-admin/src/main/resources/application.yaml index 9fd9dd23..73756c51 100644 --- a/ghy-admin/src/main/resources/application.yaml +++ b/ghy-admin/src/main/resources/application.yaml @@ -125,3 +125,8 @@ jim: appKey: '' masterSecret: '' maxRetryTimes: '' + +# 百度地图应用api +baidu: + ak: 'ZQTgMW7W0GTuE7Ripb0HDp5TqRaOI6PZ' + url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=#AK#&output=json&coordtype=wgs84ll&location=' \ No newline at end of file diff --git a/ghy-common/src/main/java/com/ghy/common/config/BaiduConfig.java b/ghy-common/src/main/java/com/ghy/common/config/BaiduConfig.java new file mode 100644 index 00000000..4f44ec42 --- /dev/null +++ b/ghy-common/src/main/java/com/ghy/common/config/BaiduConfig.java @@ -0,0 +1,32 @@ +package com.ghy.common.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 百度地图应用ak配置 + * @author clunt + */ +@Component +@ConfigurationProperties(prefix = "baidu") +public class BaiduConfig { + + private String ak; + private String url; + + public String getAk() { + return ak; + } + + public void setAk(String ak) { + this.ak = ak; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +}