/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.httpclient.Header
 *  org.apache.commons.httpclient.HttpClient
 *  org.apache.commons.httpclient.HttpMethod
 *  org.apache.commons.httpclient.NameValuePair
 *  org.apache.commons.httpclient.methods.GetMethod
 *  org.apache.commons.httpclient.methods.PostMethod
 *  org.apache.commons.lang3.StringUtils
 */
package com.hst.httpclient;

import com.hst.framework.util.HstToolsUtil;
import com.hst.httpclient.HttpClientCommon;
import com.hst.httpclient.HttpConnectionManager;
import com.hst.httpclient.HttpConstants;
import java.io.IOException;
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.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.lang3.StringUtils;

public class Test {
    public static void main(String[] args) throws Exception {
        PostMethod post = null;
        try {
            String dlzh = "362330198904264231";
            String dlmm = "123";
            if (HstToolsUtil.isNullOrEmpty(HttpConstants.HTTP_IP)) {
                HttpConstants.HTTP_IP = "80.16.52.42";
            }
            if (HttpConstants.HTTP_PORT <= 0) {
                HttpConstants.HTTP_PORT = 80;
            }
            HttpClient client = HttpConnectionManager.httpClientInstance();
            String login_url = "http://80.16.52.42/webapp/login.do";
            post = HttpClientCommon.szrsLoginPostMethod(dlzh, dlmm, login_url);
            client.executeMethod((HttpMethod)post);
            System.out.println("\u767b\u5f55StatusCode" + post.getStatusCode());
            if (post.getStatusCode() != 302) {
                System.out.println("\u767b\u5f55\u5931\u8d25");
                return;
            }
            Header locationHeader = post.getResponseHeader("location");
            String location = null;
            if (locationHeader != null) {
                location = locationHeader.getValue();
                System.out.println("\u91cd\u5b9a\u5411 redirected to:" + location);
            }
            String retStr = post.getResponseBodyAsString();
            System.out.println(retStr);
            String oid = null;
            String gzjslist_url = "http://80.16.52.42/webapp/pskh/gzjs/GzjsAction.do?state=gzjsList&condition(nd)=2016&condition(yf)=12";
            GetMethod method = new GetMethod(gzjslist_url);
            method.releaseConnection();
            client.executeMethod((HttpMethod)method);
            String response = method.getResponseBodyAsString();
            System.out.println(response);
            Map<Object, Object> map = new HashMap();
            map = Test.find(response);
            String key = "2016-12-22";
            oid = StringUtils.substringBetween((String)((String)map.get(key)), (String)"&oid=", (String)"&date=");
            System.out.println("\u4e3b\u952e" + oid);
            return;
        }
        catch (Exception e) {
            e.getStackTrace();
        }
        finally {
            if (post != null) {
                post.releaseConnection();
            }
        }
    }

    public static Map<String, String> find(String s) {
        HashMap<String, String> results = new HashMap<String, String>();
        String start = "onclick=\"window.location.href='";
        String end = "'\"><div style";
        String[] arr = StringUtils.substringsBetween((String)s, (String)start, (String)end);
        int i = 0;
        while (i < arr.length) {
            int num;
            String url = arr[i];
            System.out.println(url);
            if (!HstToolsUtil.isNullOrEmpty(url) && (num = url.indexOf("&date=")) >= 0) {
                String key = url.substring(num + 6);
                System.out.println(key);
                results.put(key, url);
            }
            ++i;
        }
        return results;
    }

    private static HttpMethod postMethod(String url) throws IOException {
        PostMethod post = new PostMethod(url);
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gbk");
        NameValuePair[] param = new NameValuePair[]{new NameValuePair("startCity", "\u676d\u5dde"), new NameValuePair("lastCity", "\u676d\u5dde"), new NameValuePair("userID", ""), new NameValuePair("theDate", "")};
        post.setRequestBody(param);
        post.releaseConnection();
        return post;
    }
}
