高德开放平台API: https://lbs.amap.com/
一、天气查询
天气查询: https://lbs.amap.com/api/webservice/guide/api/weatherinfo
adcode城市码表下载: https://lbs.amap.com/api/webservice/download
@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();
}
}
查询接口得到响应
示例代码地址:链接: https://pan.baidu.com/s/1SkMy2zfhyOMipNXkjHAfFQ 提取码: 6666
–来自百度网盘超级会员v7的分享