Преглед на файлове

新增腾讯地址解析方法

woody преди 5 месеца
родител
ревизия
354d7ec89b

+ 8 - 0
framework-location/src/main/java/com/chelvc/framework/location/LocationHandler.java

@@ -16,6 +16,14 @@ public interface LocationHandler {
      */
      */
     List<Address> addresses();
     List<Address> addresses();
 
 
+    /**
+     * 地址解析
+     *
+     * @param address 地址信息
+     * @return 地址信息
+     */
+    Address analyse(String address);
+
     /**
     /**
      * 根据IP定位地址
      * 根据IP定位地址
      *
      *

+ 6 - 0
framework-location/src/main/java/com/chelvc/framework/location/support/CacheableLocationHandler.java

@@ -10,6 +10,7 @@ import com.chelvc.framework.location.LocationHandler;
 import com.chelvc.framework.redis.context.RedisContextHolder;
 import com.chelvc.framework.redis.context.RedisContextHolder;
 import lombok.NonNull;
 import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Hex;
 
 
 /**
 /**
  * 可缓存的地址定位实现
  * 可缓存的地址定位实现
@@ -62,6 +63,11 @@ public class CacheableLocationHandler implements LocationHandler {
         return this.handler.addresses();
         return this.handler.addresses();
     }
     }
 
 
+    @Override
+    public Address analyse(@NonNull String address) {
+        return this.execute(Hex.encodeHexString(address.getBytes()), () -> this.handler.analyse(address));
+    }
+
     @Override
     @Override
     public Address ip2address(@NonNull String ip) {
     public Address ip2address(@NonNull String ip) {
         return this.execute(ip, () -> this.handler.ip2address(ip));
         return this.execute(ip, () -> this.handler.ip2address(ip));

+ 5 - 0
framework-location/src/main/java/com/chelvc/framework/location/support/DelegatingLocationHandler.java

@@ -59,6 +59,11 @@ public class DelegatingLocationHandler implements LocationHandler {
         return this.execute(LocationHandler::addresses);
         return this.execute(LocationHandler::addresses);
     }
     }
 
 
+    @Override
+    public Address analyse(@NonNull String address) {
+        return this.execute(handler -> handler.analyse(address));
+    }
+
     @Override
     @Override
     public Address ip2address(@NonNull String ip) {
     public Address ip2address(@NonNull String ip) {
         return this.execute(handler -> handler.ip2address(ip));
         return this.execute(handler -> handler.ip2address(ip));

+ 5 - 0
framework-location/src/main/java/com/chelvc/framework/location/support/JuheLocationHandler.java

@@ -77,6 +77,11 @@ public class JuheLocationHandler implements LocationHandler {
         throw new UnsupportedOperationException();
         throw new UnsupportedOperationException();
     }
     }
 
 
+    @Override
+    public Address analyse(String address) {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     @Override
     public Address ip2address(String ip) {
     public Address ip2address(String ip) {
         throw new UnsupportedOperationException();
         throw new UnsupportedOperationException();

+ 10 - 0
framework-location/src/main/java/com/chelvc/framework/location/support/TencentLocationHandler.java

@@ -39,6 +39,11 @@ public class TencentLocationHandler implements LocationHandler {
      */
      */
     private static final String LOCATION2ADDRESS_URL = "https://apis.map.qq.com/ws/geocoder/v1/?location=%s&key=%s";
     private static final String LOCATION2ADDRESS_URL = "https://apis.map.qq.com/ws/geocoder/v1/?location=%s&key=%s";
 
 
+    /**
+     * 地址解析接口地址
+     */
+    private static final String ADDRESS_ANALYSE_URL = "https://apis.map.qq.com/ws/geocoder/v1/?address=%s&key=%s";
+
     private final String key;
     private final String key;
 
 
     public TencentLocationHandler(@NonNull String key) {
     public TencentLocationHandler(@NonNull String key) {
@@ -127,6 +132,11 @@ public class TencentLocationHandler implements LocationHandler {
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
     }
     }
 
 
+    @Override
+    public Address analyse(@NonNull String address) {
+        return this.locate(ADDRESS_ANALYSE_URL, address);
+    }
+
     @Override
     @Override
     public Address ip2address(@NonNull String ip) {
     public Address ip2address(@NonNull String ip) {
         return this.locate(IP2ADDRESS_URL, ip);
         return this.locate(IP2ADDRESS_URL, ip);