对接高德开放平台API

高德开放平台API: https://lbs.amap.com/

一、天气查询

天气查询: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
adcode城市码表下载: https://lbs.amap.com/api/webservice/download
对接高德开放平台API_第1张图片

@Component
public class WeatherUtil {

    @Resource
    private GdConfig gdConfig;
    @Resource
    private RestTemplate restTemplate;

    public GdWeatherVO getWeather(String adCode) {
        String url = String.format(gdConfig.getWeatherUrl(), adCode);
        ResponseEntity<GdWeatherVO> resp = restTemplate.getForEntity(url, GdWeatherVO.class);
        if (resp.getBody() == null || !Objects.equals(resp.getBody().getStatus(), "1")) {
            throw new GdDemoException(GdDemoExceptionTypes.RPC_INVOKE_FAILED, "天气城市code=" + adCode);
        }
        return resp.getBody();
    }
}

查询接口得到响应
对接高德开放平台API_第2张图片
示例代码地址:链接: https://pan.baidu.com/s/1SkMy2zfhyOMipNXkjHAfFQ 提取码: 6666
–来自百度网盘超级会员v7的分享

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