C # and JAVA call the SMS interface to send text message instances,
Brief Introduction: WEB services can be used to send short messages to users of China Mobile, China Unicom, China Telecom, and China Netcom in real time or at regular intervals through the service platform.
Installation implementation: contact the local telecommunications and mobile departments.
Restrictions:
1. the user to be sent must be in the White List. The specific white list is maintained by the carrier.
2. There is a quota for the number of text messages. For example, if you want to send 600 messages, you need to contact the carrier if you want to increase the number of text messages.
SMS sending
Webservices name: SMServiceS
Webservices address: http: // 0.0.0.0/ESB/services/SMServiceS? Wsdl
Method definition: int sendSMXML (String SMInfo );
Method Description: send SMS messages. messages with the same configuration can be sent in batches. A maximum of 600 messages can be sent each time. Please strictly follow the xml provided in the example
SMInfo: String in xml format. The xml format is as follows:
<SM_INFOS>
<API_INFO key = "" sysPort = "" effectTime = "" specialId = "">
<SEND_INFO subcode = "extended code" priority = "priority, 1-9, 9 highest. If it is null, the default value is 5."> *
<MOBILES> phone number, separated by commas </MOBILES>
<CONTENT> text message CONTENT </CONTENT>
</SEND_INFO>
</API_INFO>
</SM_INFOS>
Worker node attributes:
Node or attribute name data type description
1 SM_INFOS Root Node
2 API_INFO API Information
3 key String authentication token
4 sysPort String whether to use the system Port 00: yes, no; default no
5 seconds tTime String text message sending time, format: YYYY-MM-DD hh: mm: ss, is empty instant
Send
6 specialId bigint is reserved for the id Association used by the user. For example, the sender id is used by the user,
The system does not interfere. It can be empty.
7. SEND_INFO
8 subcode String User-Defined subcode. The length depends on the SP number. The maximum length allowed is 20-sp.
7 specialId bigint is reserved for the id Association used by the user. For example, the sender id is used by the user,
The system does not interfere. It can be empty.
8 SEND_INFO
9 subcode String User-Defined subcode. The length depends on the SP number. The maximum length allowed is 20-sp.
Number length-extended code length-interface code length, can be blank
10 priority int priority, which is the highest among 1-9 and 9. If it is null, the default value is 5.
11 MOBILES phone number. Multiple Mobile phone numbers are separated by commas (,) and cannot be blank.
12. CONTENT package is recommended to avoid xml document structure errors caused by special characters.
Included in <! [CDATA [text message content]> medium
1.1.2 return value explanation
The return value belongs to the int type. For details, see the SMS interface return value table.
C # (note that the CMPP library is provided by the carrier and cannot be provided here)
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. services; using CMPP; namespace SMSend {// <summary> // summary of Send /// </summary> [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. // [System. web. script. services. scriptService] public class Send: System. web. services. webService {[WebMethod] public String SendMessage (string phonenumber, string content) {string [] phoneArr = null; string resvalue = ""; string url = "http: // 10.1.1.1/ESB/services/SMService? Wsdl "; int returnvalue =-1; try {phoneArr = phonenumber. split (','); foreach (string s in phoneArr) {resvalue + = s + "," ;}if (resvalue. lastIndexOf (",")> 0) {resvalue = resvalue. substring (0, resvalue. length-1);} string xml = "<SM_INFO> <API_INFO key ='' apiKey = ''secondKey ='' response tTime = ''specialId =''> "; xml + = "<SEND_INFO subcode =''> <MOBILES> "+ resvalue +" </MOBILES> <CONTENT> <! [CDATA ["+ content +"]> </CONTENT> </SEND_INFO> </API_INFO> </SM_INFO> "; LimitCMPP cmpp = new LimitCMPP (url ); returnvalue = cmpp. sendSM (xml);} catch (Exception ex) {return ("SMS sending error:" + ex. message);} return getresult (returnvalue);} String getresult (int value) {switch (value) {case 0: return "successful"; case-100: return "system error, operation failed "; case-101: return" authentication failed, token error or this token is not activated "; case-102: return" server cluster configuration error, SMS cannot be submitted "; case-103: return "Service Disabled:"; case-201: return "parameter format error"; case-202: return "access IP not in the binding list"; case-203: return "API interface does not exist"; case-204: return "xml format error"; case-205: return "some numbers cannot be correctly submitted due to errors"; case-301: return "the interface involved has been disabled"; default: return "Unknown error ";}}}}
JAVA version
Try {Service service = new Service (); Call call Call = (Call) service. createCall (); // splicing parameter String si = "<SM_INFO> <API_INFO key = \" "sysPort = \" no \ "effectTime = \" \ "specialId = \" \ ">" + "<SEND_INFO subcode = \" \ "priority = \" 5 \ "> <MOBILES> phone number </MOBILES> <CONTENT> <! [CDATA [text message CONTENT]> </CONTENT> </SEND_INFO> </API_INFO> </SM_INFO> "; // sets the call method. setOperationName ("sendSM"); // sets the call address. setTargetEndpointAddress (new java.net. URL ("http: // 127.0.0.1/ESB/services/SMServiceS? Wsdl "); // set the parameter name and parameter type call. addParameter (new QName ("SMInfo"), org. apache. axis. encoding. XMLType. SOAP_STRING, javax. xml. rpc. parameterMode. IN); // set the return value type call. setReturnType (org. apache. axis. encoding. XMLType. SOAP_INT); // execute the call int response = (Integer) call. invoke (new Object [] {si}); // print the returned value System. out. println ("-----" + response);} catch (Exception e) {e. printStackTrace ();}/* use the activation package used by axis1.4. A jaraxis-ant.jaraxis.jarcommons-discovery-0.2.jarcommons-logging-1.0.4.jarjaxrpc.jarlog4j-1.2.8.jarmail.jarsaaj.jartools.jarwsdl4j-1.5.1.jar */xmlsec. jar