From f51d9ed812d3bebfe95d0b7929e530219f243c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Fri, 18 Jun 2021 17:32:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=AB=98=E5=BE=B7key?= =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E4=BD=BF=E7=94=A8=E5=AE=8C=E5=81=9C?= =?UTF-8?q?=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../script/temp/shenjian/util/GaoDeUtils.groovy | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 494e0cb22..5adde74e3 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 @@ -8,7 +8,7 @@ import com.fangjia.script.util.GeoHelper import com.fangjia.script.util.HttpRequestUtil import com.fangjia.script.yinjihaun.amap.GaoDeApiUtils -import java.util.concurrent.ExecutorService +import java.util.concurrent.atomic.AtomicInteger /** * 高德工具类 @@ -19,7 +19,8 @@ import java.util.concurrent.ExecutorService class GaoDeUtils { // 新获取key - def static GAO_DE_AK = "4e9592208336433ee1b7aa4d1d434418" + def static GAO_DE_AK = ["4e9592208336433ee1b7aa4d1d434418", "35925efd7333f1df52145e51b8e4e56a"] + def static AtomicInteger keyUsed = new AtomicInteger(0) def static codeNameMap = new HashMap(){{ put("150500", "地铁"); @@ -59,7 +60,7 @@ class GaoDeUtils { */ static List searchNearByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ def params = [:] - params.key = GAO_DE_AK + params.key = GAO_DE_AK[keyUsed] if (types) { params.types = types @@ -108,7 +109,7 @@ class GaoDeUtils { */ static List searchNearDtoByPoi(String city, String types, Double lng, Double lat, Integer radius, String keywords){ def params = [:] - params.key = GAO_DE_AK + params.key = GAO_DE_AK[keyUsed.intValue()] if (types) { params.types = types @@ -140,7 +141,10 @@ class GaoDeUtils { } else if (json && json.infocode && json.infocode == "10044") { //throw new RuntimeException("开发者的日访问量超限,被系统自动封停,第二天0:00会自动解封") // 多线程情况下还是exit有效果,抛异常不会停止程序 - System.exit(1) + if (keyUsed.intValue() >= GAO_DE_AK.size()) { + System.exit(1) + } + keyUsed.incrementAndGet() } else if (json && json.infocode && json.infocode == "10004") { // 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。 Thread.sleep(60000)