syndrom7/ooredoo-sms
Composer 安装命令:
composer require syndrom7/ooredoo-sms
包简介
Laravel package for Ooredoo SMS Caster API integration
README 文档
README
A Laravel package for integrating with the Ooredoo SMS Caster API (Maldives).
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
Installation
Install via Composer:
composer require syndrom7/ooredoo-sms
Publish the configuration file:
php artisan vendor:publish --tag=ooredoo-sms-config
Configuration
Add the following to your .env file:
OOREDOO_SMS_BEARER_TOKEN=your-bearer-token OOREDOO_SMS_USERNAME=your-username OOREDOO_SMS_ACCESS_KEY=your-access-key
The default endpoint is https://o-papi1-lb01.ooredoo.mv/bulk_sms/v2. You can override this in the published config file or via the OOREDOO_SMS_ENDPOINT environment variable.
Usage
Basic Usage
use Syndrom\OoredooSms\Facades\OoredooSms; // Send to single recipient OoredooSms::send('9609166818', 'Your message here'); // Send to multiple recipients OoredooSms::send(['9609166818', '9609166819'], 'Bulk message');
Fluent API
OoredooSms::to('9609166818') ->message('Your message here') ->send(); // Multiple recipients OoredooSms::to(['9609166818', '9609166819']) ->message('Bulk message') ->send();
Response Handling
The send() method returns the API response as an array:
$response = OoredooSms::send('9609166818', 'Test message');
Successful Response:
[
'response_code' => 0,
'response_message' => 'Message sent successfully',
'delivery_numbers' => '9609166818'
]
Response Fields:
response_code: Status code (0 = success)response_message: Human-readable status messagedelivery_numbers: Comma-separated list of recipient numbers
Usage Example:
$response = OoredooSms::send('9609166818', 'Your message'); if ($response['response_code'] === 0) { // SMS sent successfully $delivered = $response['delivery_numbers']; } else { // Handle error $error = $response['response_message']; }
Error Handling
The package throws OoredooSmsException for validation errors and API failures:
use Syndrom\OoredooSms\Exceptions\OoredooSmsException; try { OoredooSms::send('9609166818', 'Your message'); } catch (OoredooSmsException $e) { // Handle error Log::error('SMS failed: ' . $e->getMessage()); }
Testing
composer test
Configuration Options
The following options are available in config/ooredoo-sms.php:
| Option | Description | Default |
|---|---|---|
endpoint |
API endpoint URL | https://o-papi1-lb01.ooredoo.mv/bulk_sms/v2 |
bearer_token |
Bearer token for authentication | From .env |
username |
Ooredoo account username | From .env |
access_key |
API access key | From .env |
timeout |
HTTP request timeout (seconds) | 30 |
License
MIT License. See LICENSE for details.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-14