Java--webservice Send Verification SMS

Source: Internet
Author: User

One, SMS platform--inexplicable SMS

Www.duanxin.cm/api.html

The platform can add suffixes and its own definition of the sending content, the user received an example of text messages are as follows:

123456 "Circle Technology"

Second, WebService core code

This is the implementation layer code under the SPRINGMVC framework, and the annotations are all inside.

@Servicepublic  class SendPhoneMessageServiceImpl implements SendPhoneMessageService{          @Autowired     private MessageMapper  Messagemapper;        public resultobject sendsms (SMSParams  message)     {        ResultObject  Resultobject = new resultobject ();         Resultobject.setresultcode (resultcode.failed);                 //cell phone number validity judgment         if (!isMobile ( Message.getphonenumber ())) {             Resultobject.setresultmsg (resultmsg.msg_checkphone_failed);             return resultobject;        }                 //get the Parameters         //  account number required to send SMS         String smsAccount =  "";         //  Password         string smspwd =   "";        //  interface address          String smsURL =  "";        //  Send Content         String smsContent =  "";                 SMSInfo messageInfo =  Messagemapper.getsmsinfo ();                 if (MESSAGEINFO&NBsp;! = null)         {             //Assignment Value             smsaccount  = messageinfo.getsmsaccount ();             smspwd     = messageinfo.getsmspwd ();             smsurl     = messageinfo.getsmsurl ();             smsContent =  Messageinfo.getsmscontent ();                                  //send content, address is not empty case             if (! Smsaccount.isempty ()  && !smsurl.isEmpty ()  && smsurl.indexof ("{account}")  != -1)              {                 try{                     smscontent = urlencoder.encode (smsContent, "UTF-8");                 }catch  ( Unsupportedencodingexception e)                  {                     e.printstacktrace ();                 }                 //using the data taken instead of the set                  smsurl = smsurl.replace ("{account}",  smsaccount)                          . Replace ("{PWD}",  smspwd)                          .replace ("{PHONE}",  Message.getphonenumber ())                          .replace ("{MESSAGE}", Smscontent);             }             //  Send short Interest              System.out.println (Smsurl);     &Nbsp;       string retvalue = requesturl (SmsURL, "UTF-8");             if (Retvalue.equals (")") {                 //Send Success                  resultobject.setresultcode (resultcode.success);                 resultobject.setresultmsg (resultmsg.msg_send_success);             }else{                 resultobject.setresultmsg (resultmsg.msg_getsmsinfo_failed);             }        }else       &nbsP; {            resultobject.setresultmsg ( resultmsg.msg_getsmsinfo_failed);        }                 return resultObject;     }            /**       *  Mobile phone number verification       *       *   @param   str      *  @return   verification by returning true       */      public static boolean ismobile ( STRING STR)  {           pattern p =  null;        Matcher m = null;         boolean b = false;     //  Verify phone number           p = pattern.compile ("^[1][3,4,5,7,8][0-9]{9}$");          m = p.matcher (str);         b  = m.matches ();        return b;     }        /**      *  Network Requests      *       *  @param   String  str  requested page address      *  @param   String charSet  encoding format       *  @return  String  page return values      */     private string requesturl (String urlstr, string charset) {         //  URL address of the network          URL url = null;         //  input Stream         bufferedreader  in = null;        stringbuffer sb = new  stringbuffer ();        try{             url = new url (URLSTR);             in = new bufferedreader ( new inputstreamreader ( Url.openstream (), CharSet)  );             String str = null;            while ((Str = in.readline ())  != null)  {                      sb.append (str);             }        } catch  (Exception ex)  {            ex.printstacktrace ();             system.out.println (Ex.getMessage ());         } finally{             try{                 if (in!=null)  {                     in.close ();                 }             }catch (exception Ex)  {            }         }        String result =  Sb.tostring ();         system.out.println (Result);         return result;    }


Java--webservice Send Verification SMS

Related Article

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.