SMS Authentication Platform Interface Invocation instance

Source: Internet
Author: User
Tags md5 encryption


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/" &Gt;<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

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.