webregul / sms-ru-client
sms.ru client
Requires
- php: ^8.0
- ext-json: *
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-12-01 00:13:21 UTC
README
Contents:
Installation
Install this package with Composer:
composer require webregul/sms-ru-client
Usage
Configuration
Package provide simple configuration, just fill SmsRuConfig with follow configuration:
require __DIR__ . '/vendor/autoload.php'; $api = new \Kafkiansky\SmsRu\SmsRuApi( new \Kafkiansky\SmsRu\SmsRuConfig( [ 'api_id' => 'XXXXX-XXXX-XXXXX', 'test' => 1, 'json' => 1, ] ), new \GuzzleHttp\Client() );
Put test
parameter to 1 to prevent real money spending in test environment.
You also can use your login/password to make requests, but it safe just when using https:
$api = new \Kafkiansky\SmsRu\SmsRuApi( new \Kafkiansky\SmsRu\SmsRuConfig( [ 'login' => 'secret', 'password' => 'secret', 'test' => 1, 'json' => 1, ] ), new \GuzzleHttp\Client() );
Available methods
Send
- One client - one message
require __DIR__ . '/vendor/autoload.php'; $api = new \Kafkiansky\SmsRu\SmsRuApi( new \Kafkiansky\SmsRu\SmsRuConfig( [ 'api_id' => 'XXXXX-XXXX-XXXXX', 'test' => 1, 'json' => 1, ] ), new \GuzzleHttp\Client() ); $response = $api->send( new \Kafkiansky\SmsRu\Message\SmsRuMessage( new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello') ) );
- Many clients - one message
$response = $api->send( new \Kafkiansky\SmsRu\Message\SmsRuMessage( new \Kafkiansky\SmsRu\Message\To(['7909000000', '7909111111'], 'Hello') ) );
- Many clients - many messages
$response = $api->send( new \Kafkiansky\SmsRu\Message\SmsRuMessage( new \Kafkiansky\SmsRu\Message\Multi([ new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello'), new \Kafkiansky\SmsRu\Message\To('7909111111', 'Bonjour'), ]) ) );
The SmsRuMessage has many other parameters: you can specify user ip, ttl, time, daytime and translit. Read documentation for a full explanation. Usage is simple:
$response = $api->send( (new \Kafkiansky\SmsRu\Message\SmsRuMessage( new \Kafkiansky\SmsRu\Message\Multi([ new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello'), new \Kafkiansky\SmsRu\Message\To('7909111111', 'Bonjour'), ]) )) ->enableDaytime() ->enableTranslit() ->withTime(1000) );
Or use static call:
$response = $api->send( \Kafkiansky\SmsRu\Message\SmsRuMessage::fromRecipient( new \Kafkiansky\SmsRu\Message\Multi([ new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello'), new \Kafkiansky\SmsRu\Message\To('7909111111', 'Bonjour'), ]) ) ->enableDaytime() ->enableTranslit() ->withTime(1000) );
If need, you can use iconv to convert encoding, just put true
as second argument in Multi
type:
new \Kafkiansky\SmsRu\Message\Multi([ new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello'), new \Kafkiansky\SmsRu\Message\To('7909111111', 'Bonjour'), ], true);
And as third argument in To
:
new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello', true);
Cost
You can get cost for batch of messages:
$response = $api->cost( new \Kafkiansky\SmsRu\Message\SmsRuMessage( new \Kafkiansky\SmsRu\Message\Multi([ new \Kafkiansky\SmsRu\Message\To('7909000000', 'Hello'), new \Kafkiansky\SmsRu\Message\To('7909111111', 'Bonjour'), ]) ) ); echo $response->getTotalCost();
Balance
$response = $api->balance(); echo $response->getBalance();
Limit
$response = $api->limit(); echo $response->getTotalLimit(); echo $response->getUsedToday();
Senders
$response = $api->senders(); echo $response->getSenders();
Testing
$ composer test
License
The MIT License (MIT). See License File for more information.