package com.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

/**
 * @author 作者姓名: dubaohui
 * @version 创建时间：2015-9-1 下午3:36:20
 * 类说明
 */
public class SendMessage {
	private  final static String action="interfaceSms";
	private final static String account = "N00000002010";
	private final static String password = "bvff334f3x5ids";
	private final static String sign = "太e车";
	private final static String md5="81f0e1f0-32df-11e3-a2e6-1d21429e5f46";
	public static boolean sendcode(String phone,String context){
		boolean flg = false;
		try{
			String url = "http://115.29.14.183:3000/openService";
			HttpPost httppost = new HttpPost(url);
			List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("action", action));
			params.add(new BasicNameValuePair("account", account));
			params.add(new BasicNameValuePair("password", password));
			params.add(new BasicNameValuePair("num", phone));
			params.add(new BasicNameValuePair("sign",sign));
			params.add(new BasicNameValuePair("content", context+" 退订请回T"));
			params.add(new BasicNameValuePair("md5", md5));
			httppost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
			HttpResponse response = new DefaultHttpClient().execute(httppost);
			if (response.getStatusLine().getStatusCode() == 200) {
				String result = EntityUtils.toString(response.getEntity());
				JSONObject json = new JSONObject(result);
				flg = json.getBoolean("success");
			}
			}catch(Exception ex){
				ex.printStackTrace();
			}
		return flg;
	}
	
	 public static void main(String[] args) {
	    	System.out.println(sendcode("13764935808", "尊敬的车商您好！ 退订请回T"));
	    }
	
}
