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