package com.fastbee.data.controller.printer.yilianyun;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fastbee.common.exception.ServiceException;

import java.util.Map;

public class YiLianYunBaseService {
    /**
     * 基本请求
     * @param body 请求负载
     * @return 请求结果 data
     */
    public JSONObject baseRequest(String url, Map<String,Object> body){
        String jsonStr = JSONUtil.toJsonStr(body);
        String respStr = HttpUtil.post(url, jsonStr);
        JSONObject resp = JSONUtil.parseObj(respStr);
        System.err.println(resp);
        if(!resp.get("error").toString().equals("0")){
            throw new ServiceException(resp.get("error_description").toString());
        }
        return resp.getJSONObject("body");
    }
}
