PHP code example of prihod / alphasms-client

1. Go to this page and download the library: Download prihod/alphasms-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prihod / alphasms-client example snippets




use AlphaSMS\Client;

fb-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);
...