09_短信发送

1 sms.webchinese.cn/default.shtml


2 访问上面的路径注册用户


3 看api接口说明
public class SendMsg_webchinese {

public static void main(String[] args) throws Exception {

HttpClient client = new HttpClient();
PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");
post.addRequestHeader("Content-Type",
"application/x-www-form-urlencoded;charset=gbk");// 在头文件中设置转码
NameValuePair[] data = { new NameValuePair("Uid", "alangwen"),
//注意这个秘钥是错误的需要正确的秘钥
//登录这个网站获取正确的秘钥 http://sms.webchinese.com.cn
new NameValuePair("Key", "3e807709c1b123451251d"),
new NameValuePair("smsMob", "13240414892"),
new NameValuePair("smsText", "验证码:8888 我是文建迎晚上好【某某公司】") };
//我是文建迎晚上好【kaitai公司】
post.setRequestBody(data);

client.executeMethod(post);
Header[] headers = post.getResponseHeaders();
int statusCode = post.getStatusCode();
System.out.println("statusCode:" + statusCode);
for (Header h : headers) {
System.out.println(h.toString());
}
String result = new String(post.getResponseBodyAsString().getBytes("utf-8"));
System.out.println(result); // 打印返回消息状态

post.releaseConnection();

}

}

猜你喜欢

转载自javawjy.iteye.com/blog/2358607