<?php

use infobip\SmsClient;
use infobip\utils\OneApiDateTime;
require_once __DIR__ . '/../vendor/autoload.php';
date_default_timezone_set("UTC");
$fromTime = OneApiDateTime::createFromFormat('Y-m-dTH:i:s....O', '1970-01-01T00:00:00.000+0000');
$toTime = new DateTime();
$messageId = sizeof($argv) >= 4 ? $argv[3] : null;
$smsClient = new SmsClient(USERNAME, PASSWORD);
$messages = $smsClient->retrieveOutboundMessages($fromTime, $toTime, $messageId);
foreach ($messages->logs as $message) {
    echo "Message: \n";
    echo "\tSend Date Time: " . $message->sendDateTime . "\n";
    echo "\tMessage Id: " . $message->messageId . "\n";
    echo "\tSMS Count: " . $message->smsCount . "\n";
    echo "\tDestaination Address: " . $message->destinationAddress . "\n";
    echo "\tSender Address: " . $message->sender . "\n";
    echo "\tClient Metadata: " . $message->clientMetadata . "\n";
    echo "\tMessage Text: " . $message->messageText . "\n";
    echo "\tStatus: \n";
    echo "\t\tId: " . $message->status->id . "\n";
    echo "\t\tStatus: " . $message->status->status . "\n";
    echo "\t\tDescription: " . $message->status->description . "\n";
    echo "\t\tFailure Reason: " . $message->status->failureReason . "\n";
    echo "\tBulkId: " . $message->bulkId . "\n";
    echo "\tDelivery Report Time: " . $message->deliveryReportTime . "\n";
    echo "\tPorted: " . $message->ported . "\n";
    echo "\tPrice:\n";
    echo "\t\tPrice: " . $message->pricePerMessage->price . "\n";
    echo "\t\tCurrency: " . $message->pricePerMessage->currency . "\n";
<?php

/**
 * Subscribe and unsubscribe to MO (mobile originated messages) events.
 *
 * Use ../examples.php to test this file
 */
use infobip\models\MoSubscription;
use infobip\SmsClient;
use infobip\utils\Logs;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$smsClient->login();
// Get all current subscriptions:
$moSubscriptions = $smsClient->retrieveInboundMessagesSubscriptions();
echo 'Success:', $moSubscriptions->isSuccess(), "\n";
echo 'Found ', sizeof($moSubscriptions->subscriptions), ' subscriptions', "\n";
if (!$moSubscriptions->isSuccess()) {
    echo 'Error getting the list of subscriptions';
    die;
}
// Remove them one by one:
foreach ($moSubscriptions->subscriptions as $subscription) {
    print $subscription;
    $deleteSubscriptionResult = $smsClient->cancelInboundMessagesSubscription($subscription->subscriptionId);
    echo $deleteSubscriptionResult->isSuccess(), "\n";
}
// Create new subscriptions:
$moSubscription = new MoSubscription();
$moSubscription->notifyURL = MO_NOTIFY_URL;
$moSubscription->callbackData = 'any string';
<?php

use infobip\models\MoSubscription;
use infobip\models\SMSRequest;
use infobip\SmsClient;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$smsClient->login();
// Keyword to be used for MO messages:
$criteria = 'test' . rand(10000000, 100000000);
// Create new subscriptions:
$moSubscription = new MoSubscription();
$moSubscription->notifyURL = MO_NOTIFY_URL;
$moSubscription->callbackData = 'any string';
$moSubscription->criteria = $criteria;
$moSubscription->destinationAddress = MO_NUMBER;
// This step usually will be needed only once per application:
$createSubscriptionsResult = $smsClient->subscribeToInboundMessagesNotifications($moSubscription);
echo 'create subscriptions result:', $createSubscriptionsResult, "\n";
// Now that the subscription is saved, the application will push messages starting with $criteria and sent to $moNumber to $notifyURL
// Let's try to send a message ourselves (usually this will be done by the end user from a real mobile phone):
$smsMessage = new SMSRequest();
$smsMessage->senderAddress = '38598123456';
$smsMessage->address = $moSubscription->destinationAddress;
$smsMessage->message = $criteria . ' Some message';
$smsMessageSendResult = $smsClient->sendSMS($smsMessage);
echo 'The message is created, and you should receive a http push on ' . $moSubscription->notifyURL;
<?php

/**
 * Send message and check for delivery status until it is delivered.
 *
 * Use ../examples.php to test this file
 */
use infobip\models\SMSRequest;
use infobip\OneApiConfigurator;
use infobip\SmsClient;
use infobip\utils\Logs;
require_once __DIR__ . '/../vendor/autoload.php';
# example:initialize-sms-client
OneApiConfigurator::setCredentials(USERNAME, PASSWORD);
OneApiConfigurator::setCharset("ISO-8859-1");
$smsClient = new SmsClient();
# ----------------------------------------------------------------------------------------------------
# example:login-sms-client
$smsClient->login();
# ----------------------------------------------------------------------------------------------------
# example:prepare-message-without-notify-url
$smsMessage = new SMSRequest();
$smsMessage->senderAddress = SENDER_ADDRESS;
$smsMessage->address = DESTINATION_ADDRESS;
$smsMessage->message = 'Hell� world';
# ----------------------------------------------------------------------------------------------------
# example:send-message
$smsMessageSendResult = $smsClient->sendSMS($smsMessage);
# ----------------------------------------------------------------------------------------------------
//
# example:send-message-client-correlator
<?php

use infobip\models\SMSRequest;
use infobip\SmsClient;
require_once 'app.php';
if (!getFormParam('from') || !getFormParam('to') || !getFormParam('message')) {
    redirectWithFormError('send-message-form.php', 'From, to and message are mandatory');
}
// Construct the sms message object:
$message = new SMSRequest();
$message->senderAddress = getFormParam('from');
$message->address = getFormParam('to');
$message->message = getFormParam('message');
$message->notifyURL = getFormParam('notifyURL');
// Initialize the client:
$smsClient = new SmsClient(USERNAME, PASSWORD);
try {
    $result = $smsClient->sendSMS($message);
    redirectWithFormSuccess('send-message-form.php', '<h1>Message sent</h1><a href="check-delivery-status-form.php?clientCorrelator=' . $result->clientCorrelator . '">check delivery status</a>');
    return;
} catch (Exception $e) {
    redirectWithFormError('send-message-form.php', 'Error sending message:' . $e->getMessage());
    return;
}
<?php

use infobip\SmsClient;
require_once 'app.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$result = $smsClient->retrieveInboundMessages();
$result->inboundSMSMessage;
?>
<html>
    <head>
        <title>Inbound messages</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h1>Inbound messages</h1>
        <?php 
if ($result->inboundSMSMessage) {
    ?>
            <ul>
                <?php 
    foreach ($result->inboundSMSMessage as $message) {
        ?>
                   <li/> Message <b><?php 
        echo $message->message;
        ?>
</b> from <b><?php 
        echo $message->senderAddress;
        ?>
</b>.
                <?php 
    }
<?php

use infobip\SmsClient;
require_once '../oneapi/client.php';
$json = '{"deliveryInfoNotification":{"deliveryInfo":{"address":"tel:38598123456","deliveryStatus":"DeliveredToTerminal"},"callbackData":"1234"}}';
$status = SmsClient::unserializeDeliveryStatus($json);
assert($status->callbackData == "1234");
<?php

/**
 * Send message and check for delivery status untill it is delivered.
 *
 * Use ../examples.php to test this file
 */
use infobip\models\SMSRequest;
use infobip\SmsClient;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$smsClient->login();
# example:prepare-message-with-notify-url
$smsMessage = new SMSRequest();
$smsMessage->senderAddress = SENDER_ADDRESS;
$smsMessage->address = DESTINATION_ADDRESS;
$smsMessage->message = 'Hello world';
$smsMessage->notifyURL = NOTIFY_URL;
# ----------------------------------------------------------------------------------------------------
$smsMessageSendResult = $smsClient->sendSMS($smsMessage);
$clientCorrelator = $smsMessageSendResult->clientCorrelator;
echo NOTIFY_URL;
echo $clientCorrelator;
<?php

use infobip\SmsClient;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$smsClient->login();
# example:retrieve-inbound-messages
$inboundMessages = $smsClient->retrieveInboundMessages();
foreach ($inboundMessages->inboundSMSMessage as $message) {
    echo $message->dateTime;
    echo $message->destinationAddress;
    echo $message->messageId;
    echo $message->message;
    echo $message->resourceURL;
    echo $message->senderAddress;
}
# ----------------------------------------------------------------------------------------------------
<?php

use infobip\models\MoSubscription;
use infobip\models\SMSRequest;
use infobip\SmsClient;
use infobip\utils\Logs;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
// Keyword to be used for MO messages:
$criteria = 'test' . rand(10000000, 100000000);
// Create new subscriptions:
$moSubscription = new MoSubscription();
// Do not set notifyURL property for this one!
// $moSubscription->notifyURL = ...;
$moSubscription->callbackData = 'any string';
$moSubscription->criteria = $criteria;
$moSubscription->destinationAddress = MO_NUMBER;
// This step usually will be needed only once per application:
$createSubscriptionsResult = $smsClient->subscribeToInboundMessagesNotifications($moSubscription);
// Now that the subscription is saved, the application will store messages starting with $criteria and sent to $moNumber for you
// Let's try to send a message ourselves (usually this will be done by the end user from a real mobile phone):
$smsMessage = new SMSRequest();
$smsMessage->senderAddress = '38598123456';
$smsMessage->address = $moSubscription->destinationAddress;
$smsMessage->message = $criteria . ' Some message';
$smsMessageSendResult = $smsClient->sendSMS($smsMessage);
// Sleep a few seconds just to be sure the message is processed:
echo 'Waiting for the message to be processed...';
sleep(20);
// Note: the time lag depends on a lot of things. Usually a few seconds will be OK, but it depends on the
// client roaming status, Newtorks, etc.
<?php

use infobip\SmsClient;
require_once 'app.php';
$clientCorrelator = getFormParam('clientCorrelator');
if (!$clientCorrelator) {
    redirectWithFormError('check-delivery-status-form.php', 'Client correlator is mandatory');
}
// Initialize the client:
$smsClient = new SmsClient(USERNAME, PASSWORD);
try {
    $result = $smsClient->queryDeliveryStatus($clientCorrelator);
    redirectWithFormSuccess('check-delivery-status-form.php', '<h1>Delivery status is ' . $result->deliveryInfo[0]->deliveryStatus . '</h1>');
    return;
} catch (Exception $e) {
    redirectWithFormError('check-delivery-status-form.php', 'Error sending message:' . $e->getMessage());
    return;
}
<?php

use infobip\models\SubscribeToDeliveryNotificationsRequest;
use infobip\SmsClient;
use infobip\utils\Logs;
require_once __DIR__ . '/../vendor/autoload.php';
$smsClient = new SmsClient(USERNAME, PASSWORD);
$smsClient->login();
// Keyword to be used for MO messages:
$criteria = 'test' . rand(10000000, 100000000);
$request = new SubscribeToDeliveryNotificationsRequest();
$request->senderAddress = SENDER_ADDRESS;
$request->criteria = $criteria;
$request->notifyURL = NOTIFY_URL;
$request->criteria = 'test' . rand(10000000, 100000000);
$subscriptionResult = $smsClient->subscribeToDeliveryStatusNotifications($request);
if (!$subscriptionResult->isSuccess()) {
    echo 'Error subscribing';
    Logs::printLogs();
    die;
}
echo 'Subscribed to delivery reports sent to ', $request->senderAddress, ' reports for messages starting with ', $criteria, ' will be pushed to ', $request->notifyURL, "\n";
// List all currently active subscriptions:
$subscriptions = $smsClient->retrieveDeliveryNotificationsSubscriptions();
echo 'Found ', sizeof($subscriptions->deliveryReceiptSubscriptions), ' subscriptions', "\n";
foreach ($subscriptions->deliveryReceiptSubscriptions as $subscription) {
    // When needed, you can unsubscribe:
    $cancelResponse = $smsClient->cancelInboundMessagesSubscription($subscription->subscriptionId);
    if (!$cancelResponse->isSuccess()) {
        echo 'Error unsubscribing';
        Logs::printLogs();
<?php

/*
 * When the message is called with the notifyURL param, we will push an HTTP
 * request. This is the script to process this request.
 */
use infobip\SmsClient;
require_once __DIR__ . '/../vendor/autoload.php';
define(FILE_NAME, '../delivery-' . mktime(true));
# example:on-delivery-notification
$result = SmsClient::unserializeDeliveryStatus();
// Process $result here, e.g. just save it to a file:
$f = fopen(FILE_NAME, 'w');
fwrite($f, "\n-------------------------------------\n");
fwrite($f, 'status: ' . $result->deliveryInfo->deliveryStatus . "\n");
fwrite($f, 'address: ' . $result->deliveryInfo->address . "\n");
fwrite($f, 'messageId: ' . $result->deliveryInfo->messageId . "\n");
fwrite($f, 'clientCorrelator: ' . $result->deliveryInfo->clientCorrelator . "\n");
fwrite($f, 'callback data: ' . $result->callbackData . "\n");
fwrite($f, "\n-------------------------------------\n");
fclose($f);
# ----------------------------------------------------------------------------------------------------
echo 'OK';
Exemple #14
0
<?php

use infobip\SmsClient;
require_once __DIR__ . '/../vendor/autoload.php';
define(FILE_NAME, '../message-' . mktime(true));
# example:on-mo
// returns a single message not array of messages
$inboundMessages = SmsClient::unserializeInboundMessages();
// Process $inboundMessages here, e.g. just save it to a file:
$f = fopen(FILE_NAME, 'w');
fwrite($f, "\n-------------------------------------\n");
fwrite($f, 'dateTime: ' . $inboundMessages->dateTime . "\n");
fwrite($f, 'destinationAddress: ' . $inboundMessages->destinationAddress . "\n");
fwrite($f, 'messageId: ' . $inboundMessages->messageId . "\n");
fwrite($f, 'message: ' . $inboundMessages->message . "\n");
fwrite($f, 'resourceURL: ' . $inboundMessages->resourceURL . "\n");
fwrite($f, 'senderAddress: ' . $inboundMessages->senderAddress . "\n");
# ----------------------------------------------------------------------------------------------------
echo 'OK';