package com.weaver.seconddev.interfaces.workflow.action;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.lang.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;

/**
 * 调用API平台
 */
public class SendPostRequest_API extends BaseBean {

    private static final Logger logger_8c2343 = LoggerFactory.getLogger(SendPostRequest_API.class);

    public String getResult(JSONObject returnJson, String url, String appKey) {

        logger_8c2343.info(String.valueOf("SendPostRequest_API getResult "));
        HttpPost post = null;
        String result = "E";
        try {
            HttpClient client = new DefaultHttpClient();
            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
            post.setHeader("Accept", "application/json; charset=UTF-8");
            post.setHeader("appKey", appKey);
            StringEntity entity = new StringEntity(returnJson.toString(), "UTF-8");
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            logger_8c2343.info(String.valueOf("SendPostRequest_API---rspCode" + rspCode));
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            logger_8c2343.info(String.valueOf("调用接口出错" + e.toString()));
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        logger_8c2343.info(String.valueOf("SendPostRequest_API---result" + result));
        return result;
    }
}
