当前位置: 移动技术网 > IT编程>开发语言>Java > java实现发送手机短信

java实现发送手机短信

2019年07月22日  | 移动技术网IT编程  | 我要评论
本文主要研究了java语言发送手机,分享给大家,供大家参考,具体内容如下 java发送手机短信,流传有几种方法: (1)使用webservice接口发送手机短信

本文主要研究了java语言发送手机,分享给大家,供大家参考,具体内容如下

java发送手机短信,流传有几种方法:

(1)使用webservice接口发送手机短信,这个可以使用sina提供的webservice进行发送,但是需要进行注册;
(2)使用短信mao的方式进行短信的发送,这种方式应该是比较的常用,前提是需要购买硬件设备,呵呵;
(3)使用中国网建提供的sms短信平台,我的这个小的demo,是基于这个行是发送的。 

说明:java实现发送手机短信

/**
* 说明:java实现发送手机短信
* 作者:aa00aa00
*/
package com.test.mobile;
 
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;
 
public class sendmsg_webchinese {
 
public static void main(string[] args) throws exception {
 
httpclient client = new httpclient();
postmethod post = new postmethod("http://sms.webchinese.cn/web_api/");
post.addrequestheader("content-type",
"application/x-www-form-urlencoded;charset=gbk");// 在头文件中设置转码
namevaluepair[] data = { new namevaluepair("uid", "*****"), // 注册的用户名
new namevaluepair("key", "*******"), // 注册成功后,登录网站使用的密钥
new namevaluepair("smsmob", "*********"), // 手机号码
new namevaluepair("smstext", "java程序发的信息!!") };
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(
"gbk"));
system.out.println(result);
post.releaseconnection();
}
}
 
 

运行以上的代码:就可以给自己的手机发送短信了,本人亲测,没有问题,分享给大家!

以上就是本文的全部内容,希望对大家学习java程序设计有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网