PHP code example of gelo11 / smstraffic-client

1. Go to this page and download the library: Download gelo11/smstraffic-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/ */

    

gelo11 / smstraffic-client example snippets


use Gelo11\SmsTraffic\SmsTrafficClient;
use Gelo11\SmsTraffic\SmsTrafficConfig;
use Gelo11\SmsTraffic\Client\GuzzleHttpClient;
use Gelo11\SmsTraffic\Parser\SimpleXmlResponseParser;
use Gelo11\SmsTraffic\Request\SendSmsRequest;

$config = new SmsTrafficConfig('ваш_логин', 'ваш_пароль');

$client = new SmsTrafficClient(
    $config,
    new GuzzleHttpClient(new \GuzzleHttp\Client()),
    new SimpleXmlResponseParser()
);

$request = new SendSmsRequest(
    phones: '79051112233',
    message: 'Привет!',
    originator: 'MySender',
    wantSmsIds: true
);

$response = $client->sendSms($request);
echo "Отправлено: {$response->description}\n";

use Gelo11\SmsTraffic\Exception\SmsTrafficException;
use Gelo11\SmsTraffic\Model\ErrorCode;

try {
    $client->sendSms($request);
} catch (SmsTrafficException $e) {
    if ($e->getCode() === ErrorCode::INSUFFICIENT_FUNDS) {
        // Обработка нехватки средств
    }
}

use Gelo11\SmsTraffic\Model\Status;

$status = Status::fromString('Delivered');
echo $status->isFinal() ? 'Доставлено' : 'В обработке';