<?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;
Пример #2
0
<?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;
}