高德key统一调用
This commit is contained in:
+29
-91
@@ -24,10 +24,6 @@ import java.util.concurrent.atomic.AtomicInteger
|
||||
*/
|
||||
class GaoDeUtils {
|
||||
|
||||
// 新获取key
|
||||
def static GAO_DE_AK = ["4e9592208336433ee1b7aa4d1d434418", "10bcb421d2ee4e51ed9268d6dca58ad1"]
|
||||
def static AtomicInteger keyUsed = new AtomicInteger(0)
|
||||
|
||||
def static codeNameMap = new HashMap<String, String>(){{
|
||||
put("150500", "地铁");
|
||||
put("1507", "公交");
|
||||
@@ -54,6 +50,18 @@ class GaoDeUtils {
|
||||
put("0601", "商场")
|
||||
}};
|
||||
|
||||
/**
|
||||
* 获取高德KEY
|
||||
* @return
|
||||
*/
|
||||
static String getGaodeKey() {
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("http://192.168.0.100:38080/FangJiaDataService/getAmapKey")
|
||||
if (json.status == 0 && json.result != null) {
|
||||
return json.result
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找周边配套
|
||||
* @param city
|
||||
@@ -66,7 +74,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[keyUsed]
|
||||
params.key = this.getGaodeKey()
|
||||
|
||||
if (types) {
|
||||
params.types = types
|
||||
@@ -91,17 +99,7 @@ class GaoDeUtils {
|
||||
count = json.getString("count").toInteger()
|
||||
result.addAll(DataUtil.toMongoDbObj(json.pois))
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
@@ -128,7 +126,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[keyUsed.intValue()]
|
||||
params.key = this.getGaodeKey()
|
||||
|
||||
if (types) {
|
||||
params.types = types
|
||||
@@ -158,26 +156,14 @@ class GaoDeUtils {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
break;
|
||||
} else if (json && json.infocode && json.infocode == "10017") {
|
||||
// 所请求的资源不可用
|
||||
//System.exit(1)
|
||||
Thread.sleep(60000)
|
||||
break;
|
||||
System.exit(1)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
@@ -225,7 +211,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List<AmapPoi> getAmapById(id){
|
||||
def params = [:]
|
||||
params.key = GAO_DE_AK[keyUsed.intValue()]
|
||||
params.key = this.getGaodeKey()
|
||||
params.id = id
|
||||
params.output = 'json'
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
@@ -240,23 +226,13 @@ class GaoDeUtils {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
} else if (json && json.infocode && json.infocode == "10017") {
|
||||
// 所请求的资源不可用
|
||||
//System.exit(1)
|
||||
Thread.sleep(60000)
|
||||
System.exit(1)
|
||||
}
|
||||
return Collections.emptyList()
|
||||
}
|
||||
@@ -266,7 +242,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List<AmapPoiDetail> getAmapDetailById(id){
|
||||
def params = [:]
|
||||
params.key = GAO_DE_AK[keyUsed.intValue()]
|
||||
params.key = this.getGaodeKey()
|
||||
params.id = id
|
||||
params.output = 'json'
|
||||
JSONObject json = HttpRequestUtil.getJsonContent("https://restapi.amap.com/v3/place/detail", params);
|
||||
@@ -281,23 +257,13 @@ class GaoDeUtils {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
} else if (json && json.infocode && json.infocode == "10017") {
|
||||
// 所请求的资源不可用
|
||||
//System.exit(1)
|
||||
Thread.sleep(60000)
|
||||
System.exit(1)
|
||||
}
|
||||
return Collections.emptyList()
|
||||
}
|
||||
@@ -307,7 +273,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static List searchPoi(String city, String keywords, String region, String typecodes){
|
||||
def params = [:]
|
||||
params.key = GAO_DE_AK[keyUsed.intValue()]
|
||||
params.key = this.getGaodeKey()
|
||||
params.keywords = keywords
|
||||
params.city = city
|
||||
params.region = region
|
||||
@@ -337,17 +303,7 @@ class GaoDeUtils {
|
||||
ex.printStackTrace()
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && (json.infocode == "10004" || json.infocode == "10021" || json.infocode == "10017")) {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
@@ -377,7 +333,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static def getGaoDeAddress(location) {
|
||||
Map<String, String> params = new HashMap<String, String>()
|
||||
params.put("key", GAO_DE_AK[keyUsed.intValue()])
|
||||
params.put("key", this.getGaodeKey())
|
||||
params.put("location", location)
|
||||
String content
|
||||
try {
|
||||
@@ -393,16 +349,7 @@ class GaoDeUtils {
|
||||
return regeocode.formatted_address;
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
@@ -418,7 +365,7 @@ class GaoDeUtils {
|
||||
*/
|
||||
static def parserByGaode(def city, def address) {
|
||||
Map<String, String> params = new HashMap<String, String>()
|
||||
params.put("key", GAO_DE_AK[keyUsed.intValue()])
|
||||
params.put("key", this.getGaodeKey())
|
||||
params.put("city", city)
|
||||
params.put("address", address)
|
||||
String content
|
||||
@@ -437,16 +384,7 @@ class GaoDeUtils {
|
||||
return ["lng": arrs[0], "lat": arrs[1]]
|
||||
}
|
||||
} else if (json && json.infocode && json.infocode == "10044") {
|
||||
synchronized (this) {
|
||||
for (int i = 0; i < GAO_DE_AK.size(); i++) {
|
||||
if (GAO_DE_AK[i] == params.key) {
|
||||
if (i + 1 >= GAO_DE_AK.size()) {
|
||||
System.exit(1)
|
||||
}
|
||||
keyUsed = new AtomicInteger(i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
System.exit(1)
|
||||
} else if (json && json.infocode && json.infocode == "10004") {
|
||||
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||
Thread.sleep(60000)
|
||||
|
||||
Reference in New Issue
Block a user