package com.fastbee.deviceData.api.xinzhitianqi;


import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;

/**
 * @Author wei
 * @Date 2023/5/23
 */
public class TianqiApi {

    /**
     * 获取用户所有设备信息
     */
    public static JSONObject QitianApi() {

        String url = UrlConstant.QitianApi + "?key=" +
                UrlConstant.PrivateKey +
                "&location=kenli&language=zh-Hans&unit=c";//指定URL
        HttpResponse execute = HttpUtil.createGet(url).execute();
        if (execute.getStatus() == HttpStatus.HTTP_OK) {
            JSONObject jsonObject = new JSONObject(execute.body());
//            System.out.println("jsonObject = " + jsonObject);
            return jsonObject;
        }


        return null;
    }

    /**
     * 未来15天逐日天气预报和昨日天气
     *
     * @param start 0 代表当天  当天+n
     * @param days  获取几天的数据
     * @return
     */

    public static JSONObject weatherDaily(int start, int days) {

        String url = UrlConstant.QitianApi + "?key=" +
                UrlConstant.PrivateKey +
                "&location=kenli&language=zh-Hans&unit=c&start=" + start + "&days=" + days;//指定URL
        HttpResponse execute = HttpUtil.createGet(url).execute();
        if (execute.getStatus() == HttpStatus.HTTP_OK) {
            JSONObject jsonObject = new JSONObject(execute.body());
//            System.out.println("jsonObject = " + jsonObject);
            return jsonObject;
        }


        return null;
    }
}
