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; + } +}