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

import com.alibaba.fastjson.JSONObject;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.lang.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;

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

    // public static void main(String[] args) {
    // //调用接口
    // String url = "http://10.6.105.25:8180/mes/oa/OaAuditResult.html";
    // 
    // new SendPostRequest_param().getResult("[{\"procId\":\"2274423\"}]", url);
    // 
    // 
    // }
    private static final Logger logger_10af0f96 = LoggerFactory.getLogger(SendPostRequest_param.class);

    public String getResult(Map<String, String> params, String url) {
        HttpPost post = null;
        String result = "E";
        try {
            HttpClient client = new DefaultHttpClient();
            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded; charset=UTF-8");
            post.setHeader("Accept", "multipart/form-data; charset=UTF-8");
            List<NameValuePair> mlist = new ArrayList<NameValuePair>();
            Set<String> keySet = params.keySet();
            for (String key : keySet) {
                mlist.add(new BasicNameValuePair(key, params.get(key)));
            }
            System.out.println("mlist=" + mlist);
            post.setEntity(new UrlEncodedFormEntity(mlist, "utf-8"));
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            logger_10af0f96.error(String.valueOf("SendPostRequest_param---rspCode" + rspCode));
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            logger_10af0f96.error(String.valueOf("调用接口出错" + e.toString()));
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        return result;
    }
}
