package com.seeyon.apps.ydctu8c.util;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.seeyon.apps.ydctu8c.vo.U8cResponse;
import com.seeyon.ctp.util.json.JSONUtil;

/**
 * 功能描述:<br>
 * <pre>
 *
 * </pre>
 *
 * @Author: HuangZhengguo
 * @Date: 2024/4/28
 */
public class U8cHttpUtil {

    private U8cHttpUtil() {

    }

    public static String doPost(String url, String body, String u8cSystem, String u8cUsercode,String u8cPassword,String connection,String contentType) throws Exception {

        return HttpRequest.post(url).header("accept", "*/*")
                .header("connection", connection)
                .header("Content-Type", contentType)
                .header("system", u8cSystem)
                .header("usercode", u8cUsercode)
                .header("password", u8cPassword)
                .body(body).execute().body();
    }

    public static U8cResponse parseResponse(String response) throws Exception {
        try {
            JSONObject object = JSONUtil.parseJSONString(response, JSONObject.class);
            return new U8cResponse(object);
        } catch (Exception e) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("Status", "0");
            jsonObject.put("Msg", "解析json异常");
            jsonObject.put("Data", response);
            return new U8cResponse(jsonObject);
        }
    }



    public static void main(String[] args) {
        String url = "";
    }

}
