WebService SMS Gateway Configuration

Source: Internet
Author: User
Tags wsdl

First step: WebService frame Selection "Take cxf as an example"

1,: http://cxf.apache.org/download.html, please install the JDK in advance (I use apache-cxf-2.7.18,jdk1.7)

2, the second step: Extract Apache-cxf-2.7.11.zip to the specified directory, environment variable settings: Create Cxf_home and add to Path

3. Add Wsdl2java–h under cmd

Show above results, successful

Step two: Parse the WSDL file

1, using the WSDL address provided by the SMS, right-click to save as a WSDL file (take wsdl.wsdl as an example)

2. Enter the following command in CMD

Wsdl2java-p com.ucp-d d:\\ucp-all d:\\cxf\\wsdl.wsdl generates code based on d:\\cxf\\wsdl.wsdl file, COM.UCP is the specified package name for easy copying into the actual project

3. Copy the generated code into the actual project

Step Three: Code import

Generally only need to use this Extcommandserviceporttype_extcommandservicehttpport_client.java class

 PackageCOM.UCP;/*** Please modify this class to meet your needs*/ImportJava.io.File;Importjava.net.MalformedURLException;ImportJava.net.URL;ImportJavax.xml.namespace.QName;ImportJavax.jws.WebMethod;ImportJavax.jws.WebParam;ImportJavax.jws.WebResult;ImportJavax.jws.WebService;Importjavax.xml.bind.annotation.XmlSeeAlso;ImportJavax.xml.ws.RequestWrapper;ImportJavax.xml.ws.ResponseWrapper;/*** This class is generated by Apache CXF 2.7.18 * 2017-10-12t11:23:03.075+08:00 * generated source version:2.7.18 * */ Public Final classextcommandserviceporttype_extcommandservicehttpport_client {Private Static FinalQName service_name =NewQName ("http://service.message.wiscom.com", "Extcommandservice"); Privateextcommandserviceporttype_extcommandservicehttpport_client () {} Public Static voidMain (String args[])throwsjava.lang.Exception {URL wsdlurl=extcommandservice.wsdl_location; if(Args.length > 0 && args[0]! =NULL&& "". Equals (args[0]) {File wsdlfile=NewFile (args[0]); Try {                if(Wsdlfile.exists ()) {Wsdlurl=Wsdlfile.touri (). Tourl (); } Else{wsdlurl=NewURL (args[0]); }            } Catch(malformedurlexception e) {e.printstacktrace (); }} extcommandservice SS=NewExtcommandservice (Wsdlurl, service_name); Extcommandserviceporttype Port=Ss.getextcommandservicehttpport (); {System.out.println ("Invoking Createmo ..."); Java.lang.String _createmo_in0= ""; Java.lang.String _createmo_in1= ""; Java.lang.String _createmo_in2= ""; Java.lang.Long _createmo__return=Port.createmo (_createmo_in0, _createmo_in1, _createmo_in2); System.out.println ("Createmo.result=" +_createmo__return); } {System.out.println ("Invoking CreateMessage ..."); Com.ucp.ArrayOfString _createmessage_in0=NULL; Java.lang.String _createmessage_in1= ""; Java.lang.String _createmessage_in2= ""; Java.lang.String _createmessage_in3= ""; Java.lang.Long _createmessage__return=port.createmessage (_createmessage_in0, _createmessage_in1, _createmessage_in2, _createmessage_in3); System.out.println ("Createmessage.result=" +_createmessage__return); } system.exit (0); }}

Fourth step: Call according to the code's interface

Recommended use of configuration files to load parameters

Private Static FinalLogger Logger = Logger.getlogger ("Defaultsmssender"); Private StaticString Ucpsmsurl; Private StaticString ucpmsg; Private StaticString ApiKey; Private Static FinalQName service_name =NewQName ("http://service.message.wiscom.com", "Extcommandservice"); Static{Properties prop=NewProperties (); Try{prop.load (ucpsmssender).class. getResourceAsStream ("/registerconf.properties")); Ucpsmsurl=prop.getproperty ("Ucpsmsurl"); ApiKey=prop.getproperty ("ApiKey"); } Catch(IOException e) {logger.error ("Load configuration file Exception", E); }    }

Send SMS

@Override Public BooleanSend (String Mobile, String msg) {Logger.info (String.Format ("Request to send SMS [%s,%s]", Mobile, msg)); Try{msg= Urlencoder.encode (msg, "UTF-8")); System.out.println ("Start to send SMS"); String tmp=httppost (Smsurl, "id=" +smsaccount+ "&psw=" +smspassword+ "&mobile=" +mobile+ "&msg=" +msg);            SYSTEM.OUT.PRINTLN (TMP); if(tmp!=NULL&&tmp.contains ("\" msg\ ": \" Success\ "") {System.out.println ("Success to send SMS"); return true; }        } Catch(unsupportedencodingexception e) {System.out.println ("Fail to send SMS");        E.printstacktrace (); }                return false; }

Based on the returned results, the matching

return value

error description

0

successful

1

The Submit parameter cannot be empty

2

invalid account ,

3

account password error ,

4

time format is incorrect , format: yyyy-mm-dd HH:mm:ss

20

System error

WebService SMS Gateway Configuration

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.