simialbi/yii2-websms-com

A PHP-client-library for using websms.com SMS services with yii2 framework.

Installs: 33

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 2

Open Issues: 0

Type:yii2-extension

1.0.1 2020-04-17 12:53 UTC

This package is auto-updated.

Last update: 2024-11-17 23:41:23 UTC


README

A lightweight PHP-client-library for using websms.com SMS services with yii2 framework. Reduces the complexity of network-communication between client and SMS gateway, to help save time and money for focusing on their business logic.

Latest Stable Version Total Downloads License

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require --prefer-dist simialbi/yii2-websms-com

or add

"simialbi/yii2-websms-com": "^1.0.0"

to the require section of your composer.json.

Usage

In order to use this component, you will need to:

  1. Setup component your application so that the module is available.

Setup component

return [
    // [...]
    'components' => [
        'sms' => [
            'class' => 'simialbi\yii2\websms\Connection',
            'baseUrl' => 'https://api.websms.com',
            'token' => '<your api token>',
            'sendUrl' => '/rest/smsmessaging/simple'
        ]
    ]
];

Example Usage

To send a message create a new Message instance and set at least the content and recipients.

<?php
 /** @var \simialbi\yii2\websms\Connection $sms */
$sms = Yii::$app->get('sms', true);
$message = $sms->createMessage();
$message
    ->id('my-test-id-' . uniqid())
    ->category($message::CATEGORY_INFORMATIONAL)
    ->content("This is a test\nwith multpile lines")
    ->type($message::MESSAGE_TYPE_TEXT)
    ->addRecipient('4367612345678');
$response = $message->send();

if ($response->isOk) {
    echo 'success';
} else {
    echo 'failure';
}

License

yii2-websms-com is released under MIT license. See bundled LICENSE for details.