/*
 * 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
 */
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.taxService.domain.wxfwh.PubGetPicReturnDomain;
import com.hst.taxService.domain.zjzk.ZjzkDxSendItemDomain;
import com.hst.taxService.domain.zjzk.ZjzkDxSendReqDomain;
import com.hst.taxService.service.imp.TestPost;
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.ArrayList;
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;

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

    public static void main(String[] args) throws IOException {
        ZjzkDxSendReqDomain domain = new ZjzkDxSendReqDomain();
        domain.setType("112");
        ArrayList<ZjzkDxSendItemDomain> xxnr = new ArrayList<ZjzkDxSendItemDomain>();
        ZjzkDxSendItemDomain item = new ZjzkDxSendItemDomain();
        item.setSjhm("12234");
        item.setTsnr("\u6d4b\u8bd5");
        item.setXxlx("112");
        xxnr.add(item);
        domain.setXxnr(xxnr);
        Gson gson = new Gson();
        String data = gson.toJson((Object)domain);
        System.out.println(data);
        String url = "http://bs.baishuichina.com/taxZfService/service/taxCommon!doService";
        String charset = "GBK";
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("domain.ywId", "ZJZK.yzpsCxslxx");
        params.put("domain.ParmJson", "{\"uid\":\"ea16224e51\",\"bid\":\"ZJZK.yzpsCxslxx\",\"sid\":\"\",\"kz\":\"\",\"ver\":\"1.0\",CXLB:\"1\",DJXH:\"10113307020000192505\",RQ_Q:\"2018-07-01\",RQ_Z:\"2018-08-01\"}");
        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/x-www-form-urlencoded;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"));
            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();
    }

    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;
        }
    }
}
