package com.zbf.system.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.IOException;
import java.util.Map;

/**
 * @program: rz_wms
 * @description:
 * @author: Tony.wu
 * @create: 2024-10-18 15:01
 **/


public class HttpUtils {

    public static JSONObject get(String url, Map<String, Object> queryParams, Map<String, String> headers) throws IOException {
        String body = HttpRequest.get(url).form(queryParams).addHeaders(headers).execute().body();
        return JSONUtil.parseObj(body);
    }

    public static JSONObject post(String url, Map<String, Object> queryParams, Map<String, String> headers) {
        String body = HttpRequest.post(url)
                .addHeaders(headers)
                .form(queryParams)
                .timeout(2000) // 设置超时时间为20秒
                .execute().body();
        return JSONUtil.parseObj(body);
    }

    public static JSONObject post(String url, String json, Map<String, String> headers) {
        String body = HttpRequest.post(url)
                .body(json)
                .addHeaders(headers)
                .timeout(2000) // 设置超时时间为20秒
                .execute().body();
        return JSONUtil.parseObj(body);
    }
}



