ozerich/yii2-rocketsms Yii2 component for SMS provider RocketSMS.by

yii2-rocketsms

  1. Installation
  2. Usage

Yii2 component for SMS provider RocketSMS.by

Installation

  1. The preferred way to install this extension is through composer.

    Either run

    php composer.phar require ozerich/yii2-rocketsms "*"
    

    or add

    "ozerich/yii2-rocketsms": "*"
    

    to the require section of your composer.json file.

  2. Add component configuration to your config.php

    'components' => [
        'sms' => [
            'class' => 'blakit\rocketsms\RocketSms',
            'login' => 'your_login',
            'password' => 'your_password'
        ]
    ]

Usage

Send SMS:

try {
    $response = \Yii::$app->sms->send('+375296000000', 'Test Message');
    echo 'SMS sent, message ID is ' . $response->getMessageId();
} catch (ErrorResponseException $exception) {
    echo 'Error sending SMS: ' . $exception->getError();
} catch (InvalidCredentialsException $exception) {
    echo 'RocketSMS credentials are invalid';
}

Check Balance:

try {
    $response = \Yii::$app->sms->balance();
    echo 'Your balance: ' . $response->getBalance() . 'BYN, ' . $response->getCredits() . ' SMS';
} catch (InvalidCredentialsException $exception) {
    echo 'RocketSMS credentials are invalid';
}

Get message status:

try {
    $response = \Yii::$app->sms->status('MESSAGE_ID');
    echo 'Message status: ' . $response->getStatus();
} catch (ErrorResponseException $exception) {
    echo 'Message not found';
} catch (InvalidCredentialsException $exception) {
    echo 'RocketSMS credentials are invalid';
}
0 0
1 follower
2 106 downloads
Yii Version: 2.0
License: MIT
Category: Others
Developed by: Vital Ozierski
Created on: May 19, 2018
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions