Giter VIP home page Giter VIP logo

yii2-smsc's Introduction

Smsc.ru wrapper for Yii 2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist ladamalina/yii2-smsc "*"

or add

"ladamalina/yii2-smsc": "*"

to the require section of your composer.json file.

Usage

To use sender, you should configure it in the application configuration like the following,

'components' => [
	...
	'sms' => [
        'class'    => 'ladamalina\smsc\Smsc',
        'login'     => '',  // login
        'password'   => '', // plain password or lowercase password MD5-hash
        'post' => true, // use http POST method
        'https' => true,    // use secure HTTPS connection
        'charset' => 'utf-8',   // charset: windows-1251, koi8-r or utf-8 (default)
        'debug' => false,    // debug mode
    ],
	...
],

Examples

Обычное сообщение

list($sms_id, $sms_cnt, $cost, $balance)
    = Yii::$app->sms->send_sms('79999999999', 'Ваш код для получения скидки');
/*
    возвращает массив (<id>, <количество sms>, <стоимость>, <баланс>) в случае успешной отправки
    либо массив (<id>, -<код ошибки>) в случае ошибки
*/

Проверка результата отправки

$sms = Yii::$app->sms;
$result = $sms->send_sms('79999999999', 'Ваш код для получения скидки');
if (!$sms->isSuccess($result)) {
    echo $sms->getError($result);
    die();
}

Отправка на группу номеров

// в первом параметре передаем список телефонов через запятую или точку с запятой
list($sms_id, $sms_cnt, $cost, $balance)
    = Yii::$app->sms->send_sms('79999999999,79999999990', 'Ваш код для получения скидки');

Для перевода сообщения в транслит

// в третьем параметре передаем 1
list($sms_id, $sms_cnt, $cost, $balance)
    = Yii::$app->sms->send_sms('79999999999', 'Вы сегодня неотразимы', 1);

Отправка от имени Ivan с отложенным временем доставки

// будет доставлено абоненту 01.01.2012 г. в 00:00
list($sms_id, $sms_cnt, $cost, $balance)
    = Yii::$app->sms->send_sms('79999999999', 'Вы сегодня неотразимы', 0, '0101120000', 0, 0, 'Ivan');

Для проверки статуса доставки SMS

list($status, $time) = Yii::$app->sms->get_status($sms_id, '79999999999');
// возвращает массив [ <статус>, <время изменения>, <код ошибки доставки> ]

Проверка состояния баланса

$balance = Yii::$app->sms->get_balance();
// возвращает баланс в виде строки или false в случае ошибки

Проверка стоимости sms

list($cost, $cnt)
    = Yii::$app->sms->get_sms_cost('79999999999', 'Вы сегодня неотразимы');
// возвращает массив [ <стоимость>, <количество sms> ]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.