I do the mobile phone to send text messages, is based on the interface provided by others to do, the interface content is as follows:
SMS Platform Interface Description 1, overview 1.1 Interface Description
Each system needs to call this interface when sending text messages. 1.2 interface protocols and data formats
The SMS Platform interface adopts HTTP transmission protocol, the data format is XML and the encoding is UTF-8. 1.3 Interface Address
Remote Service Invocation interface address: Http://10.0.7.40:8080/smsHttpServlet.servlet. 2, the interface detailed description 2.1 Data content for sending SMS requests
Name |
Field |
Data type |
Not empty |
Note |
Business code |
Syscode |
VARCHAR2 (10) |
Not empty |
Please obtain from the information center |
Department Code |
Depcode |
VARCHAR2 (50) |
Not empty |
Fill in: 00000000 |
Department Name |
Depname |
VARCHAR2 (50) |
Not empty |
Fill in: Ahn Wah Agricultural Insurance Co., Ltd. |
Password |
Password |
VARCHAR2 (50) |
Not empty |
Please request to the Information center, need MD5 encryption |
Receiver's cell phone number. |
Mobile |
VARCHAR2 (11) |
Not empty |
11-digit Cell phone number starting with 1 |
SMS Content |
Content |
VARCHAR2 (500) |
Not empty |
Each English or Chinese character is 1 units, up to 500 |
2.2 Send text message request XML lattice model example
<?xml version= "1.0" encoding= "UTF-8"?>
<xmlRequest>
<syscode> (Business code please request to Information Center) </syscode>
<depcode>00000000</depcode>
<depname> an China Agricultural Insurance Co., Ltd. </depname>
<password> (please send the password to the information center, please transmit MD5 password) </password>
<body>
<sms>
<mobile> Receiver Mobile Number </mobile>
<content> SMS Content </content>
</sms>
</body>
</xmlRequest> 2.3 Get the return data content of the sending result
Name |
Field |
Data type |
Not empty |
Note |
Business code |
Recode |
VARCHAR2 (10) |
Not empty |
Success: 000, failed: 001 |
2.4 Get send result return XML lattice model example
<?xml version= "1.0" encoding= "UTF-8"?>
<xmlResponse>
<recode>000</recode>
</xmlResponse> 3, Attention matters
(1) Send SMS request in the business code and password please to the information Center, and pay attention to proper custody, do not leak;
(2) It is prohibited to use all kinds of sensitive words in the text message;
(3) Please do not use the word "test" in the text message, otherwise the result of the interface return sending success, and the message is not actually issued;
(4) Send short message for charge business, please pay attention to save the use when testing.
Second, I wrote the code as follows:
First, we need to import the Commons-httpclient-3.0.jar package into the Lib directory;
Second Write call method:
/**
* Send a single message
*/
Public String SendMessage () {
try {
StringBuffer bufxml = new StringBuffer ();
Bufxml.append ("<?xml version=");
Bufxml.append ("\" 1.0\ "");
Bufxml.append ("encoding=");
Bufxml.append ("\" utf-8\ "");
Bufxml.append ("?><xmlrequest>Bufxml.append ("Business Code");
Bufxml.append ("</syscode><depcode>");
Bufxml.append ("00000000");
Bufxml.append ("</depcode><depname> An wah Agricultural Insurance Co., Ltd. </depname><password> password </password> Bufxml.append (mobile number);
Bufxml.append ("</mobile><content>");
Bufxml.append (SMS content);
Bufxml.append ("</content></sms></body></xmlRequest>");
Postmethod post = new Postmethod ("Http://10.0.7.40:8080/smsHttpServlet.servlet");//Request Address
Add XML string here
Post.setrequestbody (Bufxml.tostring ());
Specifying the type of request content
Post.setrequestheader ("Content-type", "text/xml; Charset=utf-8 ");
HttpClient httpclient = new HttpClient ();//Create Instance of HttpClient
int result;
try {
result = Httpclient.executemethod (POST);
System.out.println ("Response Status code:" + result);//return 200 for success
SYSTEM.OUT.PRINTLN ("Response body:");
System.out.println (post.getresponsebodyasstring ())//returned content
String responsexml = post.getresponsebodyasstring ();
if (! "". Equals (responsexml) && responsexml!= null) {
if (Responsexml.contains ("000")) {
System.out.println ("Send Success");
}else if (Responsexml.contains ("001")) {
System.out.println ("Send Failed"); }
}
Post.releaseconnection ()//Free connection
catch (HttpException e) {
System.out.println ("Send Failed");
E.printstacktrace ();
catch (IOException e) {
System.out.println ("Send Failed");
E.printstacktrace ();
}
catch (Exception e) {
E.printstacktrace ();
This.message = This.getfailmessage ("Send Failed");
}
return "JSON";
}