...
Code Block |
---|
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();
// SMS gateway username, password and custom reply-to URL
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 empty source address
Address destinationAddress = new Address();
destinationAddress.setType("SMS");
destinationAddress.setValue("61412345678");
Address sourceAddress = new Address();
sourceAddress.setType("SMS");
sourceAddress.setValue("");
// create 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
Document document = new Document();
document.setUsername(username);
document.setPassword(password);
document.setMessages(new Message[] {message});
document.setOptions(new SMSOption[] {});
// documentId is returned by the SMS Gateway and can be used to query the SMS Gateway
String documentId = smsService.sendDocument(document);
System.out.println("documentId=" + documentId);
// query the SMS Gateway for the status of the SMS contained within the document
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());
}
}
}
|
Application output of the above JAVA example for a successful send should look similar to the code block below. In this case the SMS addressed to 61412345678 has a state of 10 (SMS_STATE_CODE_SUBMITTED), which indicates it has been successfully submitted to the SMS Gateway.
Code Block |
---|
documentId=5682808080808080808080808080ECB501
- 61412345678, 10
|
Once the destination handset replies to the SMS, with a message such as "This is the reply". The SMS Gateway will send a HTTP GET to the reply-to address similar to the following, which can be parsed any web application at that URL:
Code Block |
---|
http://www.example.com/replyto.php?smsid=MYUNIQUEID&text=This is the reply&from=61412345678
|