@FeignClient调用第三方(高德逆向地理位置)方式

@Slf4j
@Service
public class GeoregeoServiceImpl implements IGeoregeoService {
    @Resource
    private RedisTemplate redisTemplate;
    @Autowired
    private GeoregeoServiceApi georegeoServiceApi;
    @Value("${third.service.georegeo.radius}")
    private Integer radius;
    @Value("${third.service.georegeo}")
    private String georegeoUrl;

    /**
     * 经纬度获取地理位置
     *
     * @param longitude 经度
     * @param latitude 纬度
     * @return
     */
    @Override
    public GeographicalVo queryGeographical(String longitude, String latitude) {
        if (StringUtils.isBlank(longitude) || StringUtils.isBlank(latitude)){
            throw new BusinessException(ExceptionEnum.LOCATION_NULL);
        }
        StringBuilder location = new StringBuilder();
        location.append(longitude).append(",").append(latitude);
        log.info("==> location : {}",location.toString());
        /*StringBuffer json = new StringBuffer();
        String url = "https://restapi.amap.com/v3/geocode/regeo?key=01f8f9785a4220103df5f59aca83c75e&location="+location.toString();
        try {
            URL u = new URL(url);
            URLConnection yc = u.openConnection();
            //读取返回的数据
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(),"UTF-8"));
            String inputline = null;
            while((inputline=in.readLine())!=null){
                json.append(inputline);
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("==> result : {}",json.toString());*/
        //JSON result = Feign.builder().target(GeoregeoServiceApi.class,georegeoUrl).queryLocation(location.toString(),"eb586667feb24a09c25497591d0f7e6a");
        Object result = georegeoServiceApi.queryLocation(location.toString(),"01f8f9785a4220103df5f59aca83c75e");
        log.info("==> georegeo result : {}",result);
        return null;
    }

 

//@FeignClient(value = "https://restapi.amap.com/" )
@FeignClient(url = "https://restapi.amap.com/",name = "gddt")
//@FeignClient(url = "https://www.baidu.com",name = "aaa")
public interface GeoregeoServiceApi {

    /**
     * 逆地理编码API服务地址
     * @param location 经纬度坐标 经度在前,纬度在后,经纬度间以“,”分割,经纬度小数点后不要超过 6 位。
     * @return
     */
    /*@Headers({"Content-Type: application/json", "Charset: UTF-8"})
    @RequestLine("GET v3/geocode/regeo")
    JSON queryLocation(@RequestParam("location")String location,@RequestParam("key")String key);*/

    @GetMapping("v3/geocode/regeo")
    Object queryLocation(@RequestParam("location")String location, @RequestParam("key")String key);


}
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.10.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.10.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.10.1</version>
</dependency>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值