Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 5 Next »

Examples

Using the Web Services

The web services are hosted for testing on the following URL

http://test.smartmessagingservices.net:8080/gateway/services/SMSService

In order to use the SMS service you will need to be provided with a MessageCore username and password

ASP

An example using ASP to send SMS "Hello World" to 2 recipient phone numbers

Set client = Server.CreateObject("MSSOAP.SoapClient")

client.ClientProperty("ServerHTTPRequest") = True
client.MSSoapInit("http://test.smartmessagingservices.net:8080/gateway/services/SMSService?wsdl")

Dim username
Dim password
Dim recipients(1)
Dim message
Dim documentId

username = "username"
password = "password"

recipients(0) =  "0410111111"
recipients(1) =  "0410222222"

message = "Hello World"

documentId = client.send(username, password, recipients, message)

JAVA

This is an example using JAVA to send a more advanced Document to the SMS gateway using the Web Service's sendDocument method. The code uses the mc-client.jar library, which contains useful object definitions related to the SMS gateway's WebSservices.

The example sets a custom reply-to URL that has an embedded custom ID, smsid with a value of MYUNIQUEID in this example. Such parameters may be useful for integration into existing systems and to generally keep track of custom state variables related to the SMS. The reply-to URL will be stored within the system on the initial request and sent back upon SMS reply for Two-Way accounts. Addition parameters specified in this example use replacement keywords %%TEXT%% and %%FROM%% to get the reply-to SMS text body and replying address respectively for more direct access to data.

String replyToURL = "http://www.example.com/replyto.php?smsid=MYUNIQUEID&text=%%TEXT%%&from=%%FROM%%";
import com.amethon.mc.ws.stubs.Address;
import com.amethon.mc.ws.stubs.Body;
import com.amethon.mc.ws.stubs.Destination;
import com.amethon.mc.ws.stubs.Document;
import com.amethon.mc.ws.stubs.Message;
import com.amethon.mc.ws.stubs.Payload;
import com.amethon.mc.ws.stubs.SMSOption;
import com.amethon.mc.ws.stubs.SMSServiceServiceLocator;
import com.amethon.mc.ws.stubs.SMSServiceSoapBindingStub;
import com.amethon.mc.ws.stubs.SubmitStatus;

public class SMSServiceClient {
	public static void main(String[] args) throws Exception {
		SMSServiceServiceLocator serviceLocator = new SMSServiceServiceLocator();
		SMSServiceSoapBindingStub smsService = (SMSServiceSoapBindingStub)serviceLocator.getSMSService();

		String username = "username@example.com";
		String password = "password";
		String replyToURL = "http://www.example.com/replyto.php?smsid=MYUNIQUEID&text=%%TEXT%%&from=%%FROM%%";

		// set SMS destination address and a fake source address
		Address destinationAddress = new Address();
		destinationAddress.setType("SMS");
		destinationAddress.setValue("61423282862");

		Address sourceAddress = new Address();
		sourceAddress.setType("SMS");
		sourceAddress.setValue("");

		// set destination object and replyto
		Address replyToAddress = new Address();
		replyToAddress.setType("URL");
		replyToAddress.setValue(replyToURL);

		SMSOption replyToOption = new SMSOption();
		replyToOption.setName("replyto");
		replyToOption.setValue(replyToURL);

		Destination destination	= new Destination();
		destination.setDestinationAddress(destinationAddress);
		destination.setOptions(new SMSOption[] {replyToOption});
		destination.setReferenceId("");
		destination.setSourceAddress(sourceAddress);

		// create message body and payload, ASCII text in this case
		Payload payload = new Payload();
		payload.setContent("This is the payload");
		payload.setEncoding("ASCII");
		payload.setType("TEXT");
		payload.setOptions(new SMSOption[] {});

		Body body = new Body();
		body.setPayloads(new Payload[] {payload});
		body.setType("TEXT");

		// create message object
		Message message = new Message();
		message.setDestinations(new Destination[] {destination});
		message.setBody(body);
		message.setOptions(new SMSOption[] {});
		message.setReferenceId("");
		message.setSubject("This is the message subject");

		// create document object with confirm
		Document document = new Document();
		document.setUsername(username);
		document.setPassword(password);
		document.setMessages(new Message[] {message});
		document.setOptions(new SMSOption[] {});

		String documentId = smsService.sendDocument(document);

		System.out.println("documentId=" + documentId);

		SubmitStatus[] submitStatus = smsService.query(username, password, documentId);

		for (int j=0; j<submitStatus.length; j++) {
			SubmitStatus status = submitStatus[j];
			System.out.println("  - " + status.getRecipient() + ", " + status.getStatusCode());
		}
	}

}
  • No labels