/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.google.gson.Gson
 *  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
 */
package com.hst.taxService.service.imp;

import com.google.gson.Gson;
import com.hst.common.util.Base64;
import com.hst.taxService.service.imp.TestPost;
import com.hst.taxService.service.imp.TestWxfwh;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
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;

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

    public static void main(String[] args) throws IOException {
        String url = "http://127.0.0.1:9999/taxService/service/taxSmzCommonApp!doSmzService";
        String charset = "GBK";
        HashMap<String, String> params = new HashMap<String, String>();
        Base64.byteToString(TestSmz.getBytesFromFile("D:\\head\\z1.png")).replaceAll("\r\n", "");
        String imgae1 = Base64.byteToString(TestSmz.getBytesFromFile("D:\\head\\z2.png")).replaceAll("\r\n", "");
        params.put("domain.ywId", "smz.rxsfzBd");
        params.put("domain.ParmJson", "{\"uid\":\"ea16224e51\",\"bid\":\"smz.rxsfzBd\",\"sid\":\"\",\"kz\":\"\",\"ver\":\"1.0\",xm:\"xm\",sfzhm:\"\" ,sfzzmPic:\"" + imgae1 + "\",headPic:\"" + imgae1 + "\",sjlyDm:\"2\",csrq:\"1963-01-25\",yxq_q:\"2017-01-01\",yxq_z:\"2017-01-01\",bsdt_djxh:\"1330100000\"}");
        params.put("domain.ywId", "smz.jhxtGetBsyGlqyxx");
        params.put("domain.ParmJson", "{\"sfzhm\":\"330781198603010240\",\"bid\":\"smz.jhxtGetBsyxxByqhhm\",\"ver\":\"1.0\"}");
        params.put("domain.ywId", "smz.JhxtTycxSql");
        params.put("domain.ParmJson", "{\"bsdtDjxh\":\"330781198603010240\",\"bid\":\"smz.jhxtGetBsyxxByqhhm\",\"cxSql\":\"SELECT *  FROM ticket\"}");
        String str = TestPost.doPost(url, params, charset, true);
        System.out.println(str);
    }

    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/json;charset=utf-8"));
            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"));
            System.out.println(new Gson().toJson(params));
            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 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;
        }
    }
}
