package com.test.timeout;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
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.util.EntityUtils;
import com.dlsw.test.MD5;
public class SmsUnit {
private DefaultHttpClient httpclient;
private String host = "";
private HttpPost httppost;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public SmsUnit(String host) {
super();
this.httpclient = new DefaultHttpClient();
this.host = "http://"+host;
}
private synchronized String doPost(List<NameValuePair> formparams) {
HttpEntity httpEntity = null;
try {
UrlEncodedFormEntity initEntity = new UrlEncodedFormEntity(
formparams, "UTF-8");
httppost.setEntity(initEntity);
HttpResponse response = httpclient.execute(httppost);
httpEntity = response.getEntity();
String string = EntityUtils.toString(httpEntity);
//System.out.println(string);
return string;
} catch (Exception e) {
e.printStackTrace();
}finally{
if(httpEntity!=null){
try {
httpEntity.getContent().close();
httpEntity=null;
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
// 检查Email
public void sendSdk(String accId, String accName, String accPwd,String aimcodes,String content,String schTime,String bizId,String dataType,String msgId) {
httppost = new HttpPost(host+"/send");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("accId", accId));
formparams.add(new BasicNameValuePair("accName", accName));
formparams.add(new BasicNameValuePair("accPwd", accPwd));
formparams.add(new BasicNameValuePair("aimcodes", aimcodes));
formparams.add(new BasicNameValuePair("content", content));
formparams.add(new BasicNameValuePair("schTime", schTime));
formparams.add(new BasicNameValuePair("bizId", bizId));
formparams.add(new BasicNameValuePair("dataType", dataType));
//formparams.add(new BasicNameValuePair("msgId", msgId));
try {
System.out.println(doPost(formparams));
} catch (Exception e) {
e.printStackTrace();
}
}
// 检查Email
public void qryBlalance( String accName, String accPwd,String dataType) {
httppost = new HttpPost(host+"/qryBalance");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("accName", accName));
formparams.add(new BasicNameValuePair("accPwd", accPwd));
formparams.add(new BasicNameValuePair("dataType", dataType));
try {
System.out.println(doPost(formparams));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] s) {
SmsUnit smsUnit = new SmsUnit("www.lx198.com/sdk/");
String mobiles="13592605881";
String accName="dlswSdkTest@126.com";
String accId="103049";
/*smsUnit.sendSdk(accId, accName,
MD5.getMd5String("123456"), mobiles, "新疆真美丽!", "",
BizNumberUtil.createBizId(), "json","1234");*/
smsUnit.qryBlalance(accName,
MD5.getMd5String("123456"),"");
}
}