d4rkstar/yii2-kannel

Yii 2 Kannel Http SMS

Installs: 81

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 3

Open Issues: 0

Type:yii2-extension

dev-master 2018-03-17 23:19 UTC

This package is auto-updated.

Last update: 2024-10-12 11:00:44 UTC


README

This widget will let you send SMS through the HTTP interface exposed by Kannel (http://www.kannel.org/download/kannel-userguide-snapshot/userguide.html#AEN5058).

Installation

The preferred way to install this extension is through composer.

Install

Either run

$ php composer.phar require d4rkstar/yii2-kannel "dev-master"

or add

"d4rkstar/yii2-kannel": "dev-master"

to the require section of your composer.json file.

Sample Usage

In the section components of your app/config/web.php, add:

'components' => [
    ...
    'kannel' => require(__DIR__ . '/kannel.php'),
]

Now, add a configuration file named app/config/kannel.php, and add:

<?php
use d4rkstar\kannel\HttpSms;

return [
    'class'=>'d4rkstar\kannel\HttpSms',
    'host'=>'127.0.0.1', // replace with your kannel host IP
    'port'=>13013, // replace with your kannel host Port
    'username'=>'kanneluser', // replace with your kannel User
    'password'=>'kannelpass', // replace with your kannel Password
    'dlrMask'=>HttpSms::DLR_ALL, // delivery notifications (read more below)
    'dlrUrl'=>'http://127.0.0.1/delivery.php?id=%s&status=%s' // callback delivery URL 
];
?>

Now, anywhere in your application, you can send an SMS:

<?php
    $sms_id = 1; // <-- replace this ID with the Id of your DB or unique identifier of the sms
    $from = ''; <-- put your SMS sender number here
    $to = ''; <-- put SMS recipient number here
    $body = 'Hello world!'; 
    $result  = Yii::$app->kannel->sendSingleSms($id, $from, $to, $body);
    
    switch ($result['code']) {
        case '202':
            echo "Success!";
        default:
            echo "Failure!";
    }
?>

Return Values

Delivery Reports

If you set dlrMask and dlrUrl, the HTTP request will ask Kannel to report the delivery status for the SMS. Delivery reports are sent to your application through a web callback URL: based on the type of report, Kannel will call the URL you specified in dlrUrl. So, if the URL carry in an ID parameter, the callback will carry this ID too plus the type of delivery report id.

Delivery reports are:

Kannel Check

To check kannel status, a script named check/kannel_check.php is provided. N.B.: This method is a bit insecure, but if your machines are inside a "secure" environment, there should be no problem. Put the script on the server where kannel is running and adapt it to your need. You should set the $checkUrl attribute to the URL of the kannel_check.php script.