This paper mainly studies the Java language to send mobile phones, to share with you for your reference, the specific contents are as follows
Java to send mobile phone messages, there are several ways to circulate:
(1) Use WebService interface to send SMS, this can use the webservice provided by Sina to send, but need to register;
(2) The use of SMS Mao's way to send text messages, this way should be more commonly used, the premise is the need to buy hardware equipment, hehe;
(3) using the SMS platform provided by China Network, my small demo is based on this line is sent.
Description: Java implementation to send mobile phone text messages
/** * Description: Java implementation send SMS * Author: 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 Ht
Tpclient ();
Postmethod post = new Postmethod ("http://sms.webchinese.cn/web_api/"); Post.addrequestheader ("Content-type", "APPLICATION/X-WWW-FORM-URLENCODED;CHARSET=GBK");//Set transcoding in header file NameValuePair [] data = {new Namevaluepair ("Uid", "* * *"),////Registered username new Namevaluepair ("Key", "*******")
Aluepair ("Smsmob", "*********"),//Mobile number new Namevaluepair ("Smstext", "Java program message!!")};
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 ();
}
}
Run the above code: you can send a message to their mobile phone, I test, no problem, share to everyone!
The above is the entire content of this article, I hope to learn Java program to help you.