自学内容网 自学内容网

对接高德开放平台API

高德开放平台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的分享


原文地址:https://blog.csdn.net/qq_41594280/article/details/140341216

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!