This is client library for the alphasms.ua API.
- PHP 7.4 or later
The alphasms-client can be installed using Composer by running the following command:
composer require prihod/alphasms-client
Create Client object using the following code:
<?php
use AlphaSMS\Client;
require_once __DIR__ . '/vendor/autoload.php';
$apiKey = '7d514e5b-81e9-40fb-8a9e-7105ffddd3ed';
$client = new Client($apiKey);
use AlphaSMS\Request\BalanceRequest;
use AlphaSMS\Exception\RequestException;
try {
$request = new BalanceRequest();
$response = $client->execute($request);
if ($response->isSuccess()) {
echo "Response to array:\n";
print_r($response->toArray());
echo "Response get data:\n";
print_r($response->getData());
echo "Response get all entries:\n";
print_r($response->getEntries());
echo "Response get first entry:\n";
$entry = $response->getFirstEntry();
print_r($entry);
if ($entry->isSuccess()) {
echo "Entry to array:\n";
print_r($entry->toArray());
echo "Entry get data:\n";
print_r($entry->getData());
} else {
echo "Entry Error: {$entry->getError()}";
}
} else {
echo "Response Error: {$response->getError()}";
}
} catch (RequestException $e) {
echo "Exception: {$e->getMessage()}\n";
print_r($e->request->toArray());
}
use AlphaSMS\Request\SMSRequest;
$request = (new SMSRequest())
->setPhone('380971234567')
->setSender('SMSTest')
->setMessage('Message text to be sent via SMS');
$response = $client->execute($request);
...
use AlphaSMS\Request\SMSRequest;
$requests = [];
$requests[] = (new SMSRequest())
->setPhone('380971234567')
->setSender('SMSTest')
->setMessage('Message text to be sent via SMS 1');
$requests[] = (new SMSRequest())
->setPhone('380971234568')
->setSender('SMSTest')
->setMessage('Message text to be sent via SMS 2');
$requests[] = (new SMSRequest())
->setPhone('380971234569')
->setSender('SMSTest')
->setMessage('Message text to be sent via SMS 3');
$response = $client->execute($requests);
...
use AlphaSMS\Request\ViberRequest;
$request = (new ViberRequest())
->setType(ViberRequest::TYPE_TEXT)
->setPhone('380971234567')
->setSender("ViberTest")
->setMessage("Message text to send via Viber");
$response = $client->execute($request);
...
use AlphaSMS\Request\ViberRequest;
$request = (new ViberRequest())
->setType(ViberRequest::TYPE_IMAGE)
->setPhone('380971234567')
->setSender("ViberTest")
->setImage('https://...... /storage/images/json.png');
$response = $client->execute($request);
...
use AlphaSMS\Request\ViberRequest;
$request = (new ViberRequest())
->setType(ViberRequest::TYPE_TEXT_LINK)
->setPhone('380971234567')
->setSender("ViberTest")
->setMessage("Message text to send via Viber")
->setLink('https://alphasms.ua')
->setButtonText('Test');
$response = $client->execute($request);
...
use AlphaSMS\Request\ViberRequest;
$request = (new ViberRequest())
->setType(ViberRequest::TYPE_TEXT_IMAGE_LINK)
->setPhone('380971234567')
->setSender("ViberTest")
->setMessage("Message text to send via Viber")
->setLink('https://alphasms.ua')
->setButtonText('Test')
->setImage('"https://...... /storage/images/json.png');
$response = $client->execute($request);
...
use AlphaSMS\Request\RCSRequest;
$request = (new RCSRequest())
->setPhone('380971234567')
->setSender('RCSTest')
->setMessage('Message text to be sent via RCS')
->setImage('https://alphasms.ua/storage/images/json.png')
->setLink('https://alphasms.ua')
->setButtonText('Test');
$response = $client->execute($request);
...
use AlphaSMS\Request\VoiceOTPRequest;
$request = (new VoiceOTPRequest())
->setPhone('380971234567');
$response = $client->execute($request);
...
use AlphaSMS\Request\HLRRequest;
$request = (new HLRRequest())
->setPhone('380971234567');
$response = $client->execute($request);
...
use AlphaSMS\Request\StatusMessageRequest;
$request = (new StatusMessageRequest())
->setMessageId(12332);
$response = $client->execute($request);
...
- API docs