package  org.ts.ddcs.tools;

import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.ts.ddcs.log.LogHelper;

import java.net.URI;

@Component
public class HttpRest {

    public JSONObject PostDatagram(JSONObject body, String httpUrl,String logId) {
        try {
            LogHelper.info(logId+" http post datagram " + httpUrl);
            RestTemplate restTemplate = new RestTemplate();
            JSONObject result = restTemplate.postForObject(new URI(httpUrl), body, JSONObject.class);
            return result;
        } catch (Exception e) {
            LogHelper.error(e);
            LogHelper.info(logId+" ************************  post   datagram fail !********************************");
        }
        return null;
    }

}
