package com.weaver.seconddev.interfaces.eipoa;

import com.alibaba.fastjson.JSONObject;
import com.weaver.seconddev.interfaces.prop.ConfigProp;
import com.weaver.verupgrade.general.BaseBean;
import com.weaver.verupgrade.general.Util;
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.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DidiApprovalOperate extends BaseBean {

    private static final Logger logger_d3de7351 = LoggerFactory.getLogger(DidiApprovalOperate.class);

    @Autowired
    private ConfigProp configProp;
    public String operteAppr(JSONObject object, String type) {
        HttpPost post = null;
        String result = "E";
        try {
            logger_d3de7351.error(String.valueOf("开始调用滴滴接口"));
            HttpClient client = new SSLClient();
//            String url = Util.null2String(getPropValue("htportaloaUrl", type)).trim();
            String url = configProp.getDidicreate();
            post = new HttpPost(url);
            post.setHeader(HTTP.CONTENT_TYPE, "application/json; charset=UTF-8");
            post.setHeader("Accept", "application/json; charset=UTF-8");
            logger_d3de7351.error("object"+object.toString());
            StringEntity entity = new StringEntity(object.toString(), "UTF-8");
            entity.setContentType("application/json");
            post.setEntity(entity);
            HttpResponse response = client.execute(post);
            int rspCode = response.getStatusLine().getStatusCode();
            logger_d3de7351.error(String.valueOf("DidiApprovalOperate-rspCode:" + rspCode));
            if (rspCode == 200) {
                result = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
            logger_d3de7351.error(String.valueOf(rspCode));
            logger_d3de7351.error(String.valueOf("调用滴滴接口结束"));
        } catch (Exception e) {
            logger_d3de7351.error(String.valueOf("调用门户滴滴接口出错" + e.toString()));
        } finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
        return result;
    }
}
