kafkiansky/sms-ru-client

v1.0.0 2020-05-05 07:58 UTC

This package is auto-updated.

Last update: 2024-12-08 13:26:09 UTC


README

test Software License Quality Score StyleCI Total Downloads Codecov

Contents:

Installation

Install this package with Composer:

composer require kafkiansky/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

  1. 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')
    )
);
  1. Many clients - one message
$response = $api->send(
    new \Kafkiansky\SmsRu\Message\SmsRuMessage(
        new \Kafkiansky\SmsRu\Message\To(['7909000000', '7909111111'], 'Hello')
    )
);
  1. 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.