Kaynağa Gözat

添加高德token可用列表并随机使用

DESKTOP-6LTVLN7\Liumouren 2 ay önce
ebeveyn
işleme
9c0b86d155

+ 3 - 2
src/main/java/com/skyversation/poiaddr/addquery/AddressQueryEngine.java

@@ -20,6 +20,7 @@ import org.apache.commons.codec.binary.Base64;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
 
 public class AddressQueryEngine {
 
@@ -306,7 +307,7 @@ public class AddressQueryEngine {
      * @return
      */
     public AddressResult gdSearchByName(String address) {
-        String geoUrl = Constant.AMAP_GEO_URL + "?key=" + Constant.AMAP_KEY + "&address=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&output=JSON";
+        String geoUrl = Constant.AMAP_GEO_URL + "?key=" + Constant.AMAP_KEY[ThreadLocalRandom.current().nextInt(0, 4)] + "&address=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&output=JSON";
         ResponseEntity response = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, geoUrl, null, null, 0);
         if (response != null && response.getBody() != null) {
             String body = response.getBody() + "";
@@ -335,7 +336,7 @@ public class AddressQueryEngine {
         }
         JSONArray pois = new JSONArray();
         String geoUrl =
-                Constant.AMAP_SEARCH_NAME_V3 + "?key=" + Constant.AMAP_KEY + "&types=" + Constant.AMAP_SEARCH_TYPES +
+                Constant.AMAP_SEARCH_NAME_V3 + "?key=" + Constant.AMAP_KEY[ThreadLocalRandom.current().nextInt(0, 4)] + "&types=" + Constant.AMAP_SEARCH_TYPES +
                         "&keywords=" + address + "&city=" + Constant.getAMAP_CITY_CODE() + "&offset=20";
         ResponseEntity responseEntity = AddressNetTools.getInstance().requestGetOrPost(HttpMethod.GET, geoUrl, null, null, 0);
         if (responseEntity.hasBody()) {

+ 1 - 1
src/main/java/com/skyversation/poiaddr/addquery/Constant.java

@@ -80,7 +80,7 @@ public class Constant {
 
     //    public static String AMAP_KEY = "38511ab3763ab97a10bd68ad8210933d";
 //    public static String AMAP_KEY = "28f736e6421ff3577280bdca9a0ce1d9";
-    public static String AMAP_KEY = "a91ac5c3dc208259d8a3ac971f2c2529";
+    public static String[] AMAP_KEY = new String[]{"a91ac5c3dc208259d8a3ac971f2c2529", "7a68ed576a6e2539c53b172e735cf342", "50ab96b1297395c29216150c4284704b", "2e1fa082d655f41d4643acc997709c02"};
     //    oauth和dms搭建服务器地址
     public static String ServerBaseUrl = "http://121.43.55.7:";
     //    DMS服务端口和路径