/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.google.gson.Gson
 *  net.sf.json.JSONObject
 *  org.apache.commons.httpclient.Header
 *  org.apache.commons.httpclient.HttpClient
 *  org.apache.commons.httpclient.HttpMethod
 *  org.apache.commons.httpclient.methods.PostMethod
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.apache.http.HttpEntity
 *  org.apache.http.client.ClientProtocolException
 *  org.apache.http.client.entity.EntityBuilder
 *  org.apache.http.client.methods.CloseableHttpResponse
 *  org.apache.http.client.methods.HttpPost
 *  org.apache.http.client.methods.HttpUriRequest
 *  org.apache.http.entity.ContentType
 *  org.apache.http.impl.client.CloseableHttpClient
 *  org.apache.http.impl.client.HttpClients
 *  org.apache.http.util.EntityUtils
 */
package com.hst.taxService.service.imp;

import com.google.gson.Gson;
import com.hst.common.util.Base64;
import com.hst.common.util.HstJsonUtil;
import com.hst.framework.domain.BaseBusinessDomain;
import com.hst.taxService.domain.wxfwh.PubGetPicReturnDomain;
import com.ifugle.util.export.AESUtil;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class TestDd {
    public static Log _logger = LogFactory.getLog(TestDd.class);

    public static void main(String[] args) throws Exception {
        String url = "http://dingding.baishuichina.com/taxService/dsb";
        String charset = "GBK";
        BaseBusinessDomain reqDomain = new BaseBusinessDomain();
        String str = TestDd.doPost2(url, reqDomain, charset, true);
        System.out.println(AESUtil.decryptWithUnzipFromBase64(str, "OuZzTS+xtYJVte7wcaU1hF40eHaRT+Ug/uVyqeFZ5Ww="));
    }

    public static String doPost(String url, Map<String, String> params, String charset, boolean pretty) {
        StringBuffer response;
        block10: {
            response = new StringBuffer();
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod(url);
            post.setRequestHeader(new Header("Content-type", "application/x-www-form-urlencoded;charset=gbk"));
            post.setRequestHeader(new Header("User-Agent", "Mozilla/5.0 /Windows; U; Windows NT 4.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.0"));
            if (params != null) {
                for (Map.Entry<String, String> entry : params.entrySet()) {
                    post.setParameter(entry.getKey(), entry.getValue());
                }
            }
            try {
                try {
                    client.executeMethod((HttpMethod)post);
                    if (post.getStatusCode() == 200) {
                        String line;
                        BufferedReader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), charset));
                        while ((line = reader.readLine()) != null) {
                            if (pretty) {
                                response.append(line).append(System.getProperty("line.separator"));
                                continue;
                            }
                            response.append(line);
                        }
                        reader.close();
                    }
                }
                catch (IOException e) {
                    _logger.error((Object)("\u6267\u884cHTTP Post\u8bf7\u6c42" + url + "\u65f6\uff0c\u53d1\u751f\u5f02\u5e38\uff01"), (Throwable)e);
                    post.releaseConnection();
                    break block10;
                }
            }
            catch (Throwable throwable) {
                post.releaseConnection();
                throw throwable;
            }
            post.releaseConnection();
        }
        return response.toString();
    }

    public static String doPost2(String url, BaseBusinessDomain a, String charset, boolean pretty) {
        new HashMap();
        HttpPost httppost = new HttpPost(url);
        String strResult = "";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
            String json = new Gson().toJson((Object)a);
            HttpEntity httpEntity = TestDd.buildHttpEntity("", "GBK", AESUtil.encryptWithZipToBase64(json, "OuZzTS+xtYJVte7wcaU1hF40eHaRT+Ug/uVyqeFZ5Ww="));
            httppost.setEntity(httpEntity);
            CloseableHttpResponse response = httpClient.execute((HttpUriRequest)httppost);
            if (response.getStatusLine().getStatusCode() == 200) {
                strResult = EntityUtils.toString((HttpEntity)response.getEntity());
            } else {
                String err = String.valueOf(response.getStatusLine().getStatusCode());
                strResult = String.valueOf(strResult) + "\u8bf7\u6c42\u5931\u8d25\uff0c\u9519\u8bef\u4ee3\u7801\uff1a" + err;
            }
        }
        catch (ClientProtocolException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return strResult;
    }

    protected static void getPic(String imgStr) {
        try {
            JSONObject jsonObject = JSONObject.fromObject((Object)imgStr);
            JSONObject retJson = JSONObject.fromObject((Object)jsonObject.getJSONObject("dsyyqh"));
            String resultJson = retJson.getString("retJson");
            JSONObject jsonObject1 = JSONObject.fromObject((Object)resultJson);
            PubGetPicReturnDomain domain = HstJsonUtil.jsonToBean(jsonObject1.getString("result"), PubGetPicReturnDomain.class);
            byte[] b = Base64.stringToByte(domain.getPic());
            int i = 0;
            while (i < b.length) {
                if (b[i] < 0) {
                    int n = i;
                    b[n] = (byte)(b[n] + 256);
                }
                ++i;
            }
            String imgFilePath = "d:\\Toolbar_h.png";
            FileOutputStream out = new FileOutputStream(imgFilePath);
            ((OutputStream)out).write(b);
            out.flush();
            ((OutputStream)out).close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static byte[] getBytesFromFile(String filePath) {
        File f = new File(filePath);
        if (f.isDirectory()) {
            return null;
        }
        try {
            int n;
            FileInputStream stream = new FileInputStream(f);
            ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
            byte[] b = new byte[1024];
            while ((n = stream.read(b)) != -1) {
                out.write(b, 0, n);
            }
            stream.close();
            out.close();
            return out.toByteArray();
        }
        catch (IOException iOException) {
            return null;
        }
    }

    private static HttpEntity buildHttpEntity(String clientSecret, String charSet, String requestBodyBean) {
        EntityBuilder builder = EntityBuilder.create();
        builder.setContentType(ContentType.create((String)"application/json", (String)charSet));
        builder.setContentEncoding(charSet);
        builder.setText(requestBodyBean);
        return builder.build();
    }
}
