import java.io.ioexception;import org.apache.commons.httpclient.httpclient;import Org.apache.commons.httpclient.httpexception;import org.apache.commons.httpclient.namevaluepair;import org.apache.commons.httpclient.methods.postmethod;import org.dom4j.document; import org.dom4j.DocumentException;import org.dom4j.DocumentHelper; import Org.dom4j.element; import util. stringutil;public class sendsms {private static string url = "/http 106.ihuyi.cn/webservice/sms.php?method=submit ";p Ublic static void main (String [] args ) {httpclient client = new httpclient (); postmethod method = new postmethod (URL), //client.getparams (). Setcontentcharset ("GBK"); Client.getparams (). Setcontentcharset ("UTF-8"); Method.setrequestheader ("ContentType", "application/x-www-form-urlencoded;charset=utf-8 ");int mobile_code = (int) ((Math.random () *9+1) *100000);//system.out.println (MOBILE); string content = new string ("Your captcha is:" + mobile_code + ". Please do not divulge the verification code to other people. namevaluepair[] data = {//Submit SMS new namevaluepair ("account") , "Cf_user"), new namevaluepair ("password", "******"), // Passwords can use plaintext passwords or use 32-bit MD5 encryption //new namevaluepair ("password", util. Stringutil.md5encode ("password"), new namevaluepair ("mobile", "1709142****"), new namevaluepair ("Content", content),};method.setrequestbody (data); Try {client.executemethod (method); String submitresult =method.getresponsebodyasstring ();//system.out.println (SubmitResult);/*<?xml version= "1.0" encoding= "Utf-8"? ><submitresult xmlns= "http://106.ihuyi.cn/" ≫<code>2</code><msg> Submission Success </msg><smsid>204373023</smsid></submitresult >*/document doc = documenthelper.parsetext (Submitresult); element root = doc.getrootelement (); String code = root.elementtext ("code"); String msg = root.elementtext ("msg"); String smsid = root.elementtext ("Smsid"); SYSTEM.OUT.PRINTLN (code); SYSTEM.OUT.PRINTLN (msg); System.out.println (SMSID); if ("2". Equals (code)) {System.out.println ("text message submitted successfully");}} catch (httpexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} catch (ioexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();} catch (documentexception e) {// TODO Auto-generated catch Blocke.printstacktrace ();}}}
SMS Authentication Platform Interface Invocation instance