墨迹天气调用------要把我气炸了

公司要调用一个天气的接口,最终选用阿里封装下的墨迹的API

就这个:墨迹天气(专业版CityID)全国天气_API专区_云市场-阿里云

然后在这个事例的基础上改了一个我的接口

但是一直访问不通!!!

一直没怀疑是阿里提供的东西会有问题,响应式一直是timeOut

我一直找我自己的问题,想着是不是token没配好,或者appKey什么的问题……

万万没想到是示例代码里面提供的httpUtils工具类有问题

换一个工具类就好了
 

下面是改过之后的代码,有需要的自取

 private  WheatherVO getWheatherVO(Integer cityId) {
        WheatherVO wheatherVO = null;
        String url = screenProperties.getUrl();
        String appcode = screenProperties.getAppcode();
        Map<String, Object> bodys = new HashMap<String, Object>();
        bodys.put("cityId", cityId);
        bodys.put("token", screenProperties.getToken());
        String authorization = HttpRequest.post(url)
                .header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .header("Authorization", "APPCODE "+appcode)
                .form(bodys).execute().body();

        JSONObject jsonObject = JSON.parseObject(authorization);
        JSONObject condition = jsonObject.getJSONObject("data").getJSONObject("condition");
        JSONObject city = jsonObject.getJSONObject("data").getJSONObject("city");

        Integer temp = condition.getInteger("temp");
        Integer humidity = condition.getInteger("humidity");
        String windDir = condition.getString("windDir");
        Integer windLevel = condition.getInteger("windLevel");
        String tips = condition.getString("tips");

        wheatherVO = WheatherVO.builder()
                .condition(condition.getString("condition"))
                .temp(temp + "°C")
                .humidity(humidity + "%")
                .windDir(windDir)
                .windLevel(windLevel + "级")
                .tips(tips)
                .cityName(city.getString("name"))
                .cityId(city.getInteger("id"))
                .build();
        return wheatherVO;
    }

WheatherVO:

package com.mmscm.screen.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;


@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@Builder
public class WheatherVO {


    /**
     * 城市名称
     */
    private String cityName;

    /**
     * 城市ID
     */
    private Integer cityId;

    /**
     * 温馨提示(冷热适宜,感觉很舒适)。
     */
    private String tips;

    /**
     * 温度  -12度
     */
    private String temp;

    /**
     * 湿度 (45%)
     */
    private String humidity;

    /**
     * 风力 (3级)
     */
    private String windLevel;

    /**
     * 风向 (东北风)
     */
    private String windDir;

    /**
     * 天气状况
     */
    private String condition;



}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值