@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);


}

    com.fasterxml.jackson.core
    jackson-core
    2.10.1


    com.fasterxml.jackson.core
    jackson-databind
    2.10.1


    com.fasterxml.jackson.core
    jackson-annotations
    2.10.1

 

你可能感兴趣的:(java,Java)