anlutro / bulk-sms
BulkSMS API implementation in PHP.
Installs: 24 728
Dependents: 0
Suggesters: 0
Security: 0
Stars: 36
Watchers: 5
Forks: 27
Open Issues: 2
Requires
- php: >=5.4.0
- anlutro/curl: ~1.4.6
- respect/validation: ~1.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: <6
This package is auto-updated.
Last update: 2024-12-15 02:14:30 UTC
README
A simple implementation of BulkSMS for PHP.
Includes functionality to send single or batch messages.
Installation
This package requires PHP 5.4 because I'm too lazy to type array()
. Sorry.
Using composer: composer require anlutro/bulk-sms
- list of versions is available through GitHub's tag list.
Laravel
The package includes files to make usage super easy in Laravel 4 and higher.
- Add
anlutro\BulkSms\Laravel\BulkSmsServiceProvider
to the list of providers inapp/config/app.php
. - Run
php artisan config:publish anlutro/bulk-sms
. Edit the config file inapp/config/packages/anlutro/bulk-sms
and fill in your username and password. - (optional) Add an alias for the facade by adding
'BulkSms' => 'anlutro\BulkSms\Laravel\BulkSms'
to aliases inapp/config/app.php
.
Credentials
To use this library you need create an account with Bulksms. They support several sub-sites for specific regions.
- Username : Bulksms login
- Password : Bulksms login password
- Baseurl : Bulksms sub-site to connect to (e.g. 'http://bulksms.com' or 'http://bulksms.de')
Usage
Send a single message:
$bulkSms = new anlutro\BulkSms\BulkSmsService('username', 'password', 'baseurl'); $bulkSms->sendMessage('12345678', 'Hello there!');
Send more than one message at the same time by providing an array of messages:
$message1 = new \anlutro\BulkSms\Message('12345678', 'Hi there'); $message2 = new \anlutro\BulkSms\Message('12345678', 'Hello again'); $bulkSms = new anlutro\BulkSms\BulkSmsService('username', 'password', 'baseurl'); $bulkSms->sendMessage(array($message1,$message2));
Get the status of a batch of messages:
$bulkSms = new anlutro\BulkSms\BulkSmsService('username', 'password', 'baseurl'); $bulkSms->getStatusForBatchId(693099785);
Sending unicode messages
In order to send unicode messages, make sure your message is UTF-16, convert them to hexadecimal, and specify the 'dca' parameter:
$text = 'السلام عليكم'; $encodedMessage = bin2hex(mb_convert_encoding($text, 'utf-16', 'utf-8')) ; $bulkSms->sendMessage('12345678', $encodedMessage, ['dca' => '16bit']);
Send test messages
BulkSms suports test modes (SUCCESS and FAIL) that validate the message and return defined responses without really sending out SMS. In order to send messages in test mode, run the following:
Send message that will return a success:
$bulkSms = new anlutro\BulkSms\BulkSmsService('username', 'password', 'baseurl'); $bulkSms->setTestMode(\anlutro\BulkSms\BulkSmsService::TEST_ALWAYS_SUCCEED); $bulkSms->getStatusForBatchId(693099785);
Send message that will return a failure response - and thus trigger a BulkSmsException :
$bulkSms = new anlutro\BulkSms\BulkSmsService('username', 'password', 'baseurl'); $bulkSms->setTestMode(\anlutro\BulkSms\BulkSmsService::TEST_ALWAYS_FAIL); $bulkSms->getStatusForBatchId(693099785);
In Laravel, you don't need to construct $bulkSms
, and you can replace $bulkSms->
with BulkSms::
provided you followed the installation steps above.
Contact
Open an issue on GitHub if you have any problems or suggestions.
License
The contents of this repository is released under the MIT license.