yii2-rocketsms
Yii2 component for SMS provider RocketSMS.by, (*1)
Installation
-
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require ozerich/yii2-rocketsms "*"
or add, (*4)
"ozerich/yii2-rocketsms": "*"
to the require section of your composer.json
file., (*5)
-
Add component configuration to your config.php, (*6)
'components' => [
'sms' => [
'class' => 'blakit\rocketsms\RocketSms',
'login' => 'your_login',
'password' => 'your_password'
]
]
Usage
Send SMS:, (*7)
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:, (*8)
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:, (*9)
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';
}