package com.hzya.frame.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;


/**
 * @Author lvleigang
 * @Description  请求 工具类
 * @Date 11:36 上午 2023/3/6
 * @return
 **/
public class HttpUtil {
    private final Integer timeOut = 2000;
    private final String encoding = "UTF-8";


    //url
    public HttpResponse getExecute(String url) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeOut).execute();
    }

    //encoding
    public HttpResponse getExecute(String url, String encoding) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeOut).execute();
    }
    //header
    public HttpResponse getExecute(String url,  Map<String, String> header) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeOut).execute();
    }
    //body
    public HttpResponse getExecute(String url, JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //timeout
    public HttpResponse getExecute(String url, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeout).execute();
    }
    //encoding header
    public HttpResponse getExecute(String url, String encoding,  Map<String, String> header) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeOut).execute();
    }
    //encoding body
    public HttpResponse getExecute(String url, String encoding,  JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //encoding timeout
    public HttpResponse getExecute(String url, String encoding, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeout).execute();
    }
    //header body
    public HttpResponse getExecute(String url,  Map<String, String> header, JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //header timeout
    public HttpResponse getExecute(String url,  Map<String, String> header, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeout).execute();
    }
    //body timeout
    public HttpResponse getExecute(String url,JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //encoding header body
    public HttpResponse getExecute(String url, String encoding, Map<String, String> header,JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //encoding header timeout
    public HttpResponse getExecute(String url, String encoding, Map<String, String> header, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeout).execute();
    }
    //encoding body timeout
    public HttpResponse getExecute(String url, String encoding,JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //header body timeout
    public HttpResponse getExecute(String url,Map<String, String> header, JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //encoding header body timeout
    public HttpResponse getExecute(String url, String encoding, Map<String, String> header, JSONObject body,Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }



    //url
    public HttpResponse postExecute(String url) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeOut).execute();
    }

    //encoding
    public HttpResponse postExecute(String url, String encoding) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeOut).execute();
    }
    //header
    public HttpResponse postExecute(String url,  Map<String, String> header) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeOut).execute();
    }
    //body
    public HttpResponse postExecute(String url, JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //timeout
    public HttpResponse postExecute(String url, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeout).execute();
    }
    //encoding header
    public HttpResponse postExecute(String url, String encoding,  Map<String, String> header) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeOut).execute();
    }
    //encoding body
    public HttpResponse postExecute(String url, String encoding,  JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //encoding timeout
    public HttpResponse postExecute(String url, String encoding, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).timeout(timeout).execute();
    }
    //header body
    public HttpResponse postExecute(String url,  Map<String, String> header, JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //header timeout
    public HttpResponse postExecute(String url,  Map<String, String> header, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeout).execute();
    }
    //body timeout
    public HttpResponse postExecute(String url,JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //encoding header body
    public HttpResponse postExecute(String url, String encoding, Map<String, String> header,JSONObject body) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeOut).execute();
    }
    //encoding header timeout
    public HttpResponse postExecute(String url, String encoding, Map<String, String> header, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).timeout(timeout).execute();
    }
    //encoding body timeout
    public HttpResponse postExecute(String url, String encoding,JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //header body timeout
    public HttpResponse postExecute(String url,Map<String, String> header, JSONObject body, Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
    //encoding header body timeout
    public HttpResponse postExecute(String url, String encoding, Map<String, String> header, JSONObject body,Integer timeout) {
        return  HttpRequest.get(url).charset(encoding).addHeaders(header).body(JSON.toJSONString(body)).timeout(timeout).execute();
    }
}
