How Java implements sending text messages

Source: Internet
Author: User

Today saw a demand, need to do a text messaging function, online search, there are probably these methods: (1) Use the WebService interface to send SMS, this can use the webservice provided by Sina to send, but need to register; (2) Use text message 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 Chinese network built SMS platform (application account address: http://sms.webchinese.com.cn/), Heard that the network built to provide a few free text messages, went up to try, called the next his interface (the actual call interface, is actually a copy of a code, hehe ~), the code as follows, and you share:

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 {

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");//Set transcoding in header file

namevaluepair[] data = {new Namevaluepair ("Uid", "Registered user name"),

New Namevaluepair ("Key", "key is not registered password"),

New Namevaluepair ("Smsmob", "Send phone number * * * * * * * * *"),

SMS must be a complete SMS (Details Web site) can be issued. The return has been sent successfully, but the phone has not received a text message,

Suddenly the network built to the network construction staff of the telephone, told me the reason, or good. Too much nonsense, hehe ~ ~

New Namevaluepair ("Smstext", "Sent SMS")};

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); Print return message status

Post.releaseconnection ();

}

}

Required JAR Packages

commons-codec-1.4

Commons-httpclient-3.1.jar

Commons-logging-1.1.1.jar

More

How Java implements sending text messages

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.