发短信java
package com.honghailt.dataextracter.utils.telephone;
import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
/**
* @author wzy
* @since 2015/1/13
*/
public class SendTelePhone {
private static final String INTERFACEURL = "http://www.lcqxt.com/sms.aspx";// GBK编码格式
private static final String HERDERINFO = "application/x-www-form-urlencoded;charset=gbk";// 在头文件中设置转码
private static final String action = "send";//SMS短信通注册用户名
private static final String userid ="4482";
private static final String account ="beijingruitao";
private static final String password ="";
private static final String checkcontent ="1";
public static void SendToTelePhone(String telePhone,String suggestion) {
HttpClient client = new HttpClient();
PostMethod post = new PostMethod(INTERFACEURL);
post.addRequestHeader("Content-Type", HERDERINFO);
NameValuePair[] data = { new NameValuePair("action", action),
new NameValuePair("userid", userid),
new NameValuePair("account", account),//发送的手机号码
new NameValuePair("password", password),
new NameValuePair("mobile", telePhone),
new NameValuePair("content", suggestion+"【济南洪海软件部】"),
new NameValuePair("checkcontent",checkcontent)
};//短信内容,不能出现测试性语句,比如:你好
post.setRequestBody(data);
try {
client.executeMethod(post);
} catch (IOException e) {
e.printStackTrace();
}
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:" + statusCode);//响应状态码 200 OK
for (Header h : headers) {
System.out.println(h.toString());//响应头信息
}
String result = null;
try {
result = new String(post.getResponseBodyAsString());
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result); // 打印返回消息状态 大于0 代表返回信息的条数
post.releaseConnection();
}
public static void main(String[] args) {
SendTelePhone.SendToTelePhone("13371583072", "我现在要下班了!");
System.out.println("aaaaa");
}
}