Quickly develop the program interface of the SMS application
With the increasing popularity of mobile phones and SMS in users, many IT application systems, users want to increase SMS functionality in their own application. In order to increase the function of SMS, developers need to get stable, reliable, and develop simple short message interfaces.
This article mainly tells how to develop step by step, how to open a detailed description of the website: http://www.wsms.cn/.
We provide call interface for sending short messages in two ways for call, and we also provide interfaces for receiving short messages:
Step 1: Open the account to send and receive:
Enter www.wsms.cn, register your username / password / mobile number, set the billing mobile phone number. Specific procedures see the description of the website.
Step 2: Use the simplest way: URL to send and receive short messages:
Send part:
1. Call the URL in the program and pass the call parameters to the server via the URL.
Such as: http://www.wsms.cn/ws/sms.aspx? Msg = hello & phone = 1370181 **** & sender = sungz & password = **** & tag = hello & eNCoding = GB2312
Encoding is a coding method, which can be GB2312 / UTF8 / BIG5. The default is GB2312.
The URL can be tested directly into the address bar of IE.
C # example:
Private void Button1_Click (Object Sender, System.Eventargs E)
{
System.Net.WebProxy Proxy = new system.net.WebProxy ("WS-ISA-01: 8080");
Proxy.credentials = system.net.credentialcache.defaultcredentials;
System.net.globalProxySelection.select = proxy;
System.net.httpwebrequest WR = (httpwebrequest) WebRequest.create (New Uri ("http:///www.wsms.cn/ws/sms.aspx?msg= Hello & Phone = 1370181 **** & sender = sungz & password = * *** & tag = hello code "));
WebResponse ws = wr.getResponse ();
}
2, the server will return if the success process will return:
XML Version = "1.0"?>
3. Server If you cannot successfully process will return an error message, for example:
XML Version = "1.0"?>
Receive part:
This module uses the simplest polling.
Client software constantly calls the function query whether there is a new SMS and return to the XML dataset. At the same time, if you fill in the email address, you will also send mail notifications.
The mode of call is:
Http://www.wsms.cn/ws/getsms.aspx?sender=xxxxxxxxx =xxxxxxxxxxxxxxxxXencoding=gb2312
Sender = username
Password = password
Lastid = XXX (LastID is the maximum ID of the last system to return to the short message. The system returns a short message of LastID to the short message XML)
Encoding is a coding method, which can be GB2312 / UTF8 / BIG5. The default is GB2312.
The URL can be tested directly into the address bar of IE.
Java XML analysis, as examples:
Package testsms;
Import javax.xml.parsers. *;
Import javax.xml.transform. *;
Import javax.xml.transform.dom.domsource;
Import javax.xml.transform.Stream.streamResult;
Import org.w3c.dom. *;
Import java.util. *;
Class mysms {
Public String ID, SMSID, Sender, Carrierid, ServiceId, Destination, TXT, TM, STATUS
Public mysms () {
}
}
Public class myxml {
Public myXML () {
}
Public mysms [] Parsexml ()
{
Try {
DocumentBuilderFactory DBF = DocumentBuilderFactory.newinstance ();
DocumentBuilder DB = dbf.newdocumentbuilder ();
// Document doc = db.parse ("http://www.wsms.cn/ws/getsms.aspx?sender=sungz&ssword=***&lastid=5");
Document doc = db.parse ("e: //x.xml");
// Get root elements
Element element = doc.getdocumentelement ();
// List of child nodes for root elements
Nodelist nodelist = element.getlementsBytagname ("Table");
IF (nodelist.getlength () <= 0) Return NULL;
Mysms [] SMS = new mysms [nodelist.getLength ()];
For (int i = 0; i SMS [I] = new mysms (); Element link = (element) Nodelist.Item (i); Try { SMS [i] .id = link.getElementsBytagname ("ID"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [i] .smsid = link.getElementsBytagname ("smsid"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [i] .carrierid = link.getElementsBytagname ("carrierid"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) {E.PrintStackTrace (); } Try { SMS [i] .serviceId = link.getlementsBytagname ("serviceID"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [i] .destination = link.getElementsBytagname ("destination"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [i] .txt = link.getElementsBytagname ("txt"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [i] .tm = link.getElementsBytagname ("TM"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } Try { SMS [I] .status = link.getElementsBytagname ("status"). Item (0) .GetfirstChild (). getnodevalue (); } catch (exception e) { E.PrintStackTrace (); } } Return SMS; } Catch (Exception R) { R.PrintStackTrace (); Return NULL; } } } Step 2: Use Warevice to send and receive short messages: Will introduce how to quickly develop a web application that sends SMS using the VisualStudio.net and short message interface. Download Example Code Download WinRAR programming: Step 1: Open vs.net, create an ASP.NET WebApplication: SMSWeb. Step 2: Right click on the REFERENCE of Solution Explorer to add a web reasoner) Step 3: Right-click on the REFERENCE of Solution Explorer, add a web reference, address is: http://www.wsms.cn/ws/sms.asmx. Press "Add Reference" to the project. A cn.wsms.www Web Reference will be added to the Solution Explorer of VS.NET. You can click the right click to change it into WSMS. Step 4: Send code Add: in an event handler function in a Button: Private void Button1_Click (Object Sender, System.Eventargs E) { WSMS.SMS SMS = New WSMS.SMS (); String str = sms.sendsmsms ("Hello", "137-181xxxx", "UserName", "Password", "Test"); IF (str == ") Str =" success "; Messagebox.show ("Send Results:" Str); Sendsms (String MSG, String Phone, String Sender, String Password, String Tag) is a function interface that the system is available. MSG: Message Content Phone: Phone number, there can be multiple numbers, intermediate with half angle symbols; Sender: Registered User Name Password: password TAG: Tags, you can classify the sent SMS or not. Step 4: Receive coding This module uses the simplest polling. Client software continuously calls the function query whether there is a new SMS and return to XML. At the same time, if you fill in the email address, you will also send mail notifications. You can get a dataset DataSet using the GetSMS of the interface, or you can choose to use GetSMSXML to get XML data for analysis. Others: Access to WebService via Proxy See example in the code.