Java Send SMS

Source: Internet
Author: User
Tags sendmsg

Recently in the CRM project, the first contact is to send text messages. I am through the SMS platform to send text messages, I am still a rookie, if there is said wrong also hope everyone to correct, first thank you.

1. First to the SMS platform to register the user

2. After the registration is successful, the UID and key can be found under the interface API to be modified.

GBK encoded Send interface address:
http://gbk.sms.webchinese.cn/?Uid= Site user name &key= interface security Password &smsmob= mobile phone number &smstext= SMS content
UTF-8 encoded Send interface address:
http://utf8.sms.webchinese.cn/?Uid= Site user name &key= interface security Password &smsmob= mobile phone number &smstext= SMS content
Get SMS Number interface address (UTF8):
http://sms.webchinese.cn/web_api/SMS/?Action=SMS_Num&Uid= Site user name &key= interface security Password
Get SMS Number interface address (GBK):
http://sms.webchinese.cn/web_api/SMS/GBK/?Action=SMS_Num&Uid= Site user name &key= interface security Password

After the SMS call will have the corresponding return value, you can go to the SMS official website to see the corresponding meaning of the return value.

3. Take a look at my writing tool class for sending SMS

Package com.*.*.bsm.utils;


Import com.*.*.sys.exception.sysexception;

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;


Import java.io.IOException;


/**

* Created with IntelliJ idea.

* User:administrator

* DATE:14-11-26

* Time: 2:38

* To change this template use File | Settings | File Templates.

*/

public class Sendmsg {

public static string sendmsg (string touser,string content) throws ioexception{

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", "Your UID"), New Namevaluepair ("Key", "Your Key"), New Namevaluepair ("Smsmob" , Touser), New Namevaluepair ("Smstext", content)};

Post.setrequestbody (data);

Client.executemethod (POST);

header[] headers = post.getresponseheaders ();

int statusCode = Post.getstatuscode ();

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 ();

return result;

}

}




Java Send SMS

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.