sms.at powered by
dtms Mainz

websms Entwicklertoolkit (SMS SDKs)


Die websms SDKs ermöglichen Ihnen den SMS Versand einfach, mit nur wenigen Zeilen Code, in Ihre eigene Lösung zu integrieren. Wir stellen Ihnen dafür kostenlose Toolkits zur Verfügung. Bei den Toolkits handelt es sich um eine Sammlung von Bibliotheken und Klassen, die den Versand von SMS vereinfachen und die Entwicklungszeit von Anwendungen deutlich verkürzen.


PHP SDK


<?php
  // will need JSON.phps (Service_JSON) for PHP<5.2.0  
  include "WebSmsCom_Toolkit.inc";
 
  # Modify these values to your needs
  $username             = 'your_username';
  $pass                 = 'your_password';
  $gateway_url          = 'https://api.websms.com';
 
  $recipientAddressList = array("4367612345678");
  $utf8_message_text    = "Willkommen zur BusinessPlatform SDK von websms.com! Diese Nachricht enth\xC3\xA4lt 160 Zeichen. Sonderzeichen: \xC3\xA4\xC3\xB6\xC3\xBC\xC3\x9F. Eurozeichen: \xE2\x82\xAC. Das Ende wird nun ausgez\xC3\xA4hlt43210";
 
  $maxSmsPerMessage     = 1; 
  $test                 = false; // true: do not send sms for real, just test interface
 
  try {
 
    // 1.) -- create sms client (once) ------
    $smsClient = new WebSmsCom_Client($username, $pass, $gateway_url);
    $smsClient->setVerbose(true);
 
    // 2.) -- create text message ----------------
    $message  = new WebSmsCom_TextMessage($recipientAddressList, $utf8_message_text);
 
    // 3.) -- send message ------------------
    $Response = $smsClient->send($message, $maxSmsPerMessage, $test);
 
    // show success
    print_r(array(
           "Status       : ".$Response->getStatusCode(),
           "StatusMessage: ".$Response->getStatusMessage(),
           "TransferId   : ".$Response->getTransferId(),
    ));
 
  // catch everything that's not a successfully sent message
  } catch (WebSmsCom_AuthorizationFailedException $e) {
    exit("AuthorizationFailedException caught: ".$e->getMessage()."\n");
 
  } catch (WebSmsCom_ApiException $e) {
    echo $e; // possibility to handle API status codes $e->getCode()
    exit("ApiException Exception\n");
 
  } catch (WebSmsCom_HttpConnectionException $e) {
    exit("HttpConnectionException caught: ".$e->getMessage()."HTTP Status: ".$e->getCode()."\n");
 
  } catch (WebSmsCom_UnknownResponseException $e) {
    exit("UnknownResponseException caught: ".$e->getMessage()."\n");
 
  } catch (Exception $e) {
    exit("Exception caught: ".$e->getMessage()."\n");
  }
?>



C# SDK


using System;
 
using Websms;
 
class Test
{
    static void Main()
    {
        // Create the client.
        SmsClient client = new SmsClient("username", "password", "https://api.websms.com/json");
        // Create new message with one recipient.
        TextMessage textMessage = new TextMessage(4367612345678, "Hello World!");
 
        try
        {
            // Send the message.
            MessageResponse response = client.Send(textMessage, 1, false);
            // Print the response.
            Console.WriteLine("Status message: " + response.statusMessage);
            Console.WriteLine("Status code: " + response.statusCode);
        }
        catch (Exception ex)
        {
            // Handle exceptions.
            Console.WriteLine(ex.Message);
        }
 
        Console.ReadKey();
    }
}
 



Java SDK


import at.sms.business.api.domain.sms.SenderAddressType;
import at.sms.business.sdk.client.impl.DefaultSmsClient;
import at.sms.business.sdk.domain.TextMessage;
import at.sms.business.sdk.exception.ApiException;
import at.sms.business.sdk.exception.AuthorizationFailedException;
import at.sms.business.sdk.exception.HttpConnectionException;
import at.sms.business.sdk.exception.ParameterValidationException;
 
public class SynchronousCallExample {
 
public void test() {
       try {
 
       DefaultSmsClient smsClient = new DefaultSmsClient("your
                websms-username", "your password",
               "https://api.websms.com");
 
       long[] recipients = new long[] { /* e.g, 43123456789L */ };
       String messageContent = "Hello World!";
       TextMessage textMessage = new
                TextMessage(recipients,messageContent);
 
       int maxSmsPerMessage = 1;
       boolean test = false;
 
       int statuscode = smsClient.send(textMessage,
                maxSmsPerMessage, test);
 
       if (statuscode == 2000) {
           System.out.println("Sending SMS successfully tested");
       }
 
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
 
   public static void main(String[] args) {
       SynchronousCallExample example = new SynchronousCallExample();
       example.test();
   }



C++ SDK


// Simple example sending a text message via the websms.com services.
 
#include <stdio.h>
#include <iostream>
 
#include <websms/websms.h>
 
int main() {
 
  using namespace websms;
  printf("Sending text SMS using %s ...\n", Version());
 
  // Create the client.
  SmsClient client("user", "password", "https://api.websms.com");
  // Create new message with one recipient. You can also address multiple
  // recipients by passing in a vector.
  TextMessage message(4367612345678, UTF8("Hello World!"));
 
  try {
    // Send the message.
    MessageResponse response = client.Send(message,
           1,      // Max. sms per message
           false);  // Test message?
 
    // Print the response.
    printf("Status message: %s\nStatus code: %d\n",
           response.status_message(),
           response.status_code());
 
  } catch (const Exception& e) {
    // Handle exceptions.
    fprintf(stderr, "Exception: %s \n", e.What());
  }
 
  return 0;
} 



Node.js SDK


#!/usr/bin/env node
 
var websms = require("../websmscom");
websms.isDebug = false; 
 
var username             = 'your_username';
var password             = 'your_password';
var gatewayUrl           = 'https://api.websms.com';
var recipientAddressList = ['4367612345678'];
var unicodeMessageText   = 'Willkommen zur BusinessPlatform SDK von 
  websms.com! Diese Nachricht enth\u00E4lt 160 Zeichen. Sonderzeichen: 
  \u00E4\u00F6\u00FC\u00DF. Eurozeichen: \u20ac. Das Ende wird nun 
  ausgez\u00E4hlt43210';
var maxSmsPerMessage     = 1;
var isTest               = false; // true: do not send sms but test interface
 
 
function main(){
 
  // 1.) -- create sms client (once) ------
  var myClient = new websms.Client(gatewayUrl, username, password);
 
  // 2.) -- create text message ----------------
  //     Create Message objects between try..catch to catch invalid 
  //     parameters at creation and stop further broken creations or you set 
  //     'websms.doThrowMessageCreationError = false;'
 
  var myMessage;
 
  try {
 
    myMessage = new websms.TextMessage(recipientAddressList, 
      unicodeMessageText, creationFailedCallback);
 
  } catch (e) {
    console.log('Caught message creation error: ', e.message);
    console.log('Stacktrace: ', e.stack);
    return;
  }
 
  // 3.) -- send message ------------------
  myClient.send(myMessage, maxSmsPerMessage, isTest, transferredCallback, 
    notTransferredCallback);
 
};
 
function transferredCallback(apiResponse, messageObject) {
 
    console.log("\n---- transferredCallback function called with 
      ApiResponse:\n", apiResponse);
    console.log('\n---- Related messageObject:\n', messageObject);
    var statusCode      = apiResponse.statusCode;
    var statusMessage   = apiResponse.statusMessage;
    var transferId      = apiResponse.transferId;
    var clientMessageId = apiResponse.clientMessageId;
};
 
 
function notTransferredCallback(errorObj, messageObject){
 
    console.log("\n---- notTransferredCallback function called.\n");
 
    if (errorObj.cause === 'parameter' ||
        errorObj.cause === 'authorization' ||
        errorObj.cause === 'connection' ||
        errorObj.cause === 'unknown') {
 
        console.log(errorObj.message);
        //console.log("\n---- errorObj:\n", errorObj);
 
    } else if (errorObj.cause === 'api') {
 
        // API responded, but some limit was hit 
        // statusCode and statusMessage are readable,
        // see API docs for codes
        var apiResponse = errorObj.apiResponse;
 
        var statusCode    = apiResponse.statusCode;
        var statusMessage = apiResponse.statusMessage;
 
        console.log('\n---- apiResponse:\n', apiResponse);
    }
    console.log('\n---- Related messageObject:\n', messageObject);
};
 
function creationFailedCallback(errorObj, incompleteMessageObject) {
 
    console.log("\n---- creationFailedCallback function called 
      with errorObj:\n", errorObj);
    console.log("incompleteMessageObject:", incompleteMessageObject);
};
 
main();



Python SDK


#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""
----------------------------------------------------------------------
 websms.com Gateway usage sample code
  1.) create client,
  2.) create message,
  3.) send message with client.
----------------------------------------------------------------------
"""
import sys
import traceback
import WebSmsComToolkit
 
 
#--- Modify these values to your needs ----------------
username                = 'your_username'
password                = 'your_password'
gateway_url             = 'https://api.websms.com'
recipient_address_list  = [4367612345678L]
message_text_unicode    = "Willkommen zur BusinessPlatform SDK von websms.com!
  Diese Nachricht enthält 160 Zeichen. Sonderzeichen: äöüß. Eurozeichen:
  \u20ac. Das Ende wird nun ausgezählt43210"
max_sms_per_message     = 1
 
# true: do not send sms for real, just test interface
is_test                 = False
#-------------------------------------------------------
 
def main():
 
  try:
 
    # 1.) -- create sms client (once) ------
    client         = WebSmsComToolkit.Client(gateway_url, username, password)
    client.verbose = True
 
    # 2.) -- create text message ----------------
    message = WebSmsComToolkit.TextMessage(recipient_address_list,
      message_text_unicode)
 
    # 3.) -- send message ------------------
    response = client.send(message, max_sms_per_message, is_test)
 
    print "-- Response Object --"
    print "transferId      : " + str(response.transferId)
    print "clientMessageId : " + str(response.clientMessageId)
    print "statusCode      : " + str(response.statusCode)
    print "statusMessage   : " + str(response.statusMessage)
    print "rawContent      : " + str(response.rawContent)
 
  except WebSmsComToolkit.ParameterValidationException, e:
    print "ParameterValidationException caught: " + str(e.message) + "\n"
 
  except WebSmsComToolkit.AuthorizationFailedException, e:
    print "AuthorizationFailedException caught: " + str(e.message) + "\n"
 
  except WebSmsComToolkit.ApiException, e:
    # possibility to handle API status codes e.code
    print "ApiException caught. statusMessage: " + str(e.message) + ",
      statusCode: " + str(e.code) + "\n"
 
  except WebSmsComToolkit.HttpConnectionException, e:
    print "HttpConnectionException caught: " + str(e.message) +
      "HTTP Status: " + str(e.code) + "\n"
 
  except WebSmsComToolkit.UnknownResponseException, e:
    print "UnknownResponseException caught: " + str(e.message) + "\n"
 
  except Exception, e:
    print "Exception caught: " , e
    traceback.print_exc(file=sys.stdout)
 
# END
 
# MAIN
if __name__ == '__main__':
  main() 



Ruby SDK


# Include rubygems if your ruby version is below 1.9
require "rubygems"
require "BusinessPlatformSDK"
 
# included to increase the code-readability
include At::Sms::Business::Sdk
include At::Sms::Business::Sdk::Exception
include At::Sms::Business::Sdk::Domain
 
begin
    text_message =  TextMessage.new([43123456],
        "Hey you wanna hang out?")
    sms_client = SmsClient.new("your websms-account username",
        "your password", "https://api.websms.com")
 
    max_sms_per_message = 1
    test=false
 
    return_code = sms_client.sendTextSms(text_message,
        max_sms_per_message,test)
 
    puts ("success")
 
rescue ApiException,AuthorizationFailedException,
    HttpConnectionException => e
    puts e
end



Perl SDK


#!perl
#unshift(@INC, '<path to WebSmsComToolkit.pm>');
 
use utf8;
use strict;
 
use WebSmsComToolkit;
 
# --- Modify these values to your needs ---
my $gateway_url          = 'https://api.websms.com';
my $username             = 'your username';
my $password             = 'your password';
 
my $recipients           = ['436761234567']; #insert recipients msisdn
 
my $test                 = 0; # 1: do not send sms but test interface
 
# --- 1. create client, 2. create message, 3. send message --- 
my $sms_client = WebSmsComToolkit::Client->new($gateway_url, $username, 
    $password);
$sms_client->verbose(1);
 
my $utf8_message_content = "€uro";
my $text_message = WebSmsComToolkit::TextMessage->new($recipients,
    $utf8_message_content);
 
my $max_sms_per_message = 1;
my $response = $sms_client->send($text_message, $max_sms_per_message, $test) 
    or die "LWP Connection error.";
process_response($response);
 
# --- end ---
 
sub process_response {
  my ($response) = @_;
 
  if (exists($response->{'error'})) {
 
    # HTTP or server error
    print $response->{'http_status'}."\n".$response->{'error_content'};
 
  } else {
 
    # read return values from API
    if ($response->{'statusCode'} == 2000 || 
           $response->{'statusCode'} == 2001) {
      print "SMS sent, transferId: ".$response->{'transferId'}."\n";
    } else {
      print "statusCode   : ".$response->{'statusCode'}."\n";
      print "statusMessage: ".$response->{'statusMessage'}."\n";
    }
  }
}