/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.commons.lang.StringUtils
 *  org.apache.http.HttpEntity
 *  org.apache.http.HttpResponse
 *  org.apache.http.client.entity.UrlEncodedFormEntity
 *  org.apache.http.client.methods.HttpPost
 *  org.apache.http.client.methods.HttpUriRequest
 *  org.apache.http.message.BasicNameValuePair
 *  org.apache.http.util.EntityUtils
 */
package com.hst.taxService.util;

import com.hst.taxService.util.MD5Util;
import com.hst.taxService.util.RandomUtil;
import com.hst.taxService.util.SSLClient;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class MessageUtil {
    private static final String requesturl = "http://sms.hspaas.com:8080/msgHttp/json/mt";
    private static final String requestBalanceurl = "http://sms.hspaas.com:8080/msgHttp/json/balance";
    private static final String account = "42207913537173";
    private static final String password = "h6Uo42geGtSg";

    public static String sendMessageCode(String mobile, String code) throws Exception {
        if (StringUtils.isEmpty((String)mobile)) {
            throw new Exception("\u624b\u673a\u53f7\u4e3a\u7a7a");
        }
        long timestamp = System.currentTimeMillis();
        String pass = MD5Util.MD5Encode(password + mobile + timestamp, "utf-8");
        String content = "\u3010\u6b65\u957f\u79d1\u6280\u3011\u60a8\u7684\u9a8c\u8bc1\u7801\u662f" + code + "\uff0c\u5982\u975e\u672c\u4eba\u53d1\u9001\u8bf7\u5ffd\u7565\u8be5\u4fe1\u606f\u3002";
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("account", account);
        map.put("password", pass);
        map.put("timestamps", String.valueOf(timestamp));
        map.put("mobile", mobile);
        map.put("content", URLEncoder.encode(content, "utf-8"));
        return MessageUtil.doPost(requesturl, map, "utf-8");
    }

    public static String doPost(String url, Map<String, String> map, String charset) {
        SSLClient httpClient = null;
        HttpPost httpPost = null;
        String result = null;
        try {
            HttpEntity resEntity;
            HttpResponse response;
            httpClient = new SSLClient();
            httpPost = new HttpPost(url);
            ArrayList<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
            for (Map.Entry<String, String> elem : map.entrySet()) {
                list.add(new BasicNameValuePair(elem.getKey(), elem.getValue()));
            }
            if (list.size() > 0) {
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, charset);
                httpPost.setEntity((HttpEntity)entity);
            }
            if ((response = httpClient.execute((HttpUriRequest)httpPost)) != null && (resEntity = response.getEntity()) != null) {
                result = EntityUtils.toString((HttpEntity)resEntity, (String)charset);
            }
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }

    public static void main(String[] args) {
        try {
            long timestamp = System.currentTimeMillis();
            System.out.println("tt" + timestamp);
            String mobile = "13588294068";
            String pass = MD5Util.MD5Encode(password + mobile + timestamp, "utf-8");
            System.out.println("password:" + pass);
            String code = RandomUtil.getCode(6, 0);
            String content = "\u3010\u6b65\u957f\u79d1\u6280\u3011\u60a8\u7684\u9a8c\u8bc1\u7801\u662f" + code + "\uff0c\u5982\u975e\u672c\u4eba\u53d1\u9001\u8bf7\u5ffd\u7565\u8be5\u4fe1\u606f\u3002";
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("account", account);
            map.put("password", pass);
            map.put("timestamps", String.valueOf(timestamp));
            map.put("mobile", mobile);
            map.put("content", URLEncoder.encode(content, "utf-8"));
            String str = MessageUtil.doPost(requesturl, map, "utf-8");
            System.out.println(str);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
