新增高德key多线程使用完停止

This commit is contained in:
沈健
2021-06-18 17:32:03 +08:00
parent e4ac06de8c
commit f51d9ed812
@@ -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<String, String>(){{
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)