From b86fb651ed12834be3839a0d88c753ab308c02f9 Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Mon, 18 Jul 2022 16:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96key=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temp/shenjian/util/GaoDeUtils.groovy | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy index 8a94fe7ed..2a2972c21 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/util/GaoDeUtils.groovy @@ -54,8 +54,10 @@ class GaoDeUtils { * »ñÈ¡¸ßµÂKEY * @return */ - static String getGaodeKey() { - JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey", new HashMap()) + static String getGaodeKey(String type) { + Map params = new HashMap<>(); + params.put("type", type) + JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey", params) if (json.status == 0 && json.result != null) { return json.result } @@ -74,7 +76,7 @@ class GaoDeUtils { */ static List searchNearByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ def params = [:] - params.key = this.getGaodeKey() + if (types) { params.types = types @@ -91,8 +93,10 @@ class GaoDeUtils { while (result.size() < count) { params.page = "${page}".toString() page++ + params.key = this.getGaodeKey("v3/place/around") JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); if (json == null) { + params.key = this.getGaodeKey("v3/place/around") json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v3/place/around", params); } if (json && json.info && json.info == "OK") { @@ -126,7 +130,6 @@ class GaoDeUtils { */ static List searchNearDtoByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ def params = [:] - params.key = this.getGaodeKey() if (types) { params.types = types @@ -143,8 +146,10 @@ class GaoDeUtils { while (result.size() < count) { params.page = "${page}".toString() page++ + params.key = this.getGaodeKey("v5/place/around") JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params); if (json == null) { + params.key = this.getGaodeKey("v5/place/around") json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/around", params); } if (json && json.info && json.info == "OK") { @@ -211,11 +216,12 @@ class GaoDeUtils { */ static List getAmapById(id){ def params = [:] - params.key = this.getGaodeKey() params.id = id params.output = 'json' + params.key = this.getGaodeKey("v3/place/detail") JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); if (json == null) { + params.key = this.getGaodeKey("v3/place/detail") json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); } if (json && json.info && json.info == "OK") { @@ -242,11 +248,12 @@ class GaoDeUtils { */ static List getAmapDetailById(id){ def params = [:] - params.key = this.getGaodeKey() params.id = id params.output = 'json' + params.key = this.getGaodeKey("v3/place/detail") JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); if (json == null) { + params.key = this.getGaodeKey("v3/place/detail") json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params); } if (json && json.info && json.info == "OK") { @@ -273,7 +280,6 @@ class GaoDeUtils { */ static List searchPoi(String city, String keywords, String region, String typecodes){ def params = [:] - params.key = this.getGaodeKey() params.keywords = keywords params.city = city params.region = region @@ -290,8 +296,10 @@ class GaoDeUtils { while (result.size() < count) { params.page = "${page}".toString() page++ + params.key = this.getGaodeKey("v5/place/text") JSONObject json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params); if (json == null) { + params.key = this.getGaodeKey("v5/place/text") json = HttpRequestUtil.getJsonContent("http://restapi.amap.com/v5/place/text", params); } if (json && json.info && json.info == "OK") { @@ -333,12 +341,13 @@ class GaoDeUtils { */ static def getGaoDeAddress(location) { Map params = new HashMap() - params.put("key", this.getGaodeKey()) params.put("location", location) String content try { + params.put("key", this.getGaodeKey("v3/geocode/regeo")) content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") } catch (Exception e) { + params.put("key", this.getGaodeKey("v3/geocode/regeo")) content = new HttpRequest().get("http://restapi.amap.com/v3/geocode/regeo", params, "utf-8") } net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content) @@ -365,13 +374,14 @@ class GaoDeUtils { */ static def parserByGaode(def city, def address) { Map params = new HashMap() - params.put("key", this.getGaodeKey()) params.put("city", city) params.put("address", address) String content try { + params.put("key", this.getGaodeKey("v3/geocode/geo")) content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8") } catch (Exception e) { + params.put("key", this.getGaodeKey("v3/geocode/geo")) content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8") } net.sf.json.JSONObject json = net.sf.json.JSONObject.fromObject(content) @@ -393,4 +403,8 @@ class GaoDeUtils { System.exit(1) } } + + static void main(String[] args) { + println(this.getGaodeKey("v3/geocode/geo")) + } }