qsms/qbiez-sms
最新稳定版本:v2.0.8
Composer 安装命令:
composer require qsms/qbiez-sms
包简介
Laravel package for Qbiez SMS API integration - Phone number formatting, queue support, and real-time delivery reports
README 文档
README
A modern SMS integration package for Laravel applications with comprehensive features and robust error handling.
📋 Requirements
- PHP 8.0+
- Laravel 9.x/10.x/12.x
- Composer
- Active Qbiez SMS account
🚀 Quick Start
Registration
First, register for a free account at https://sms.qbiez.com/register to obtain your API token and sender ID.
Installation Steps
- Install the package via Composer:
composer require qsms/qbiez-sms
- Add the following variables to your
.envfile:
QSMS_API_TOKEN=your_api_token_here QSMS_SENDER_ID=your_sender_id_here QSMS_API_URL=https://sms.qbiez.com/api/http/sms/send QSMS_LOGGING_ENABLED=true QSMS_DEFAULT_COUNTRY_CODE=255 QSMS_LOG_FORMAT=json QSMS_LOG_RETENTION=14 QSMS_RATE_LIMIT=30 QSMS_RATE_WINDOW=60
Basic Usage
use Qsms\QbiezSms\SendSMS; $sms = new SendSMS(); $response = $sms->send('255755270046', 'Hello World!');
⚙️ Advanced Configuration
To use advanced configuration options, follow these steps:
- Create a new file
config/qsms.phpin your Laravel project - Copy the following configuration:
return [ 'api_token' => env('QSMS_API_TOKEN', ''), 'sender_id' => env('QSMS_SENDER_ID', ''), 'api_url' => env('QSMS_API_URL', 'https://sms.qbiez.com/api/http/sms/send'), 'http' => [ 'timeout' => env('QSMS_HTTP_TIMEOUT', 30), 'retry' => [ 'times' => env('QSMS_RETRY_TIMES', 3), 'sleep' => env('QSMS_RETRY_SLEEP', 100), ], ], 'default_country_code' => env('QSMS_DEFAULT_COUNTRY_CODE', '255'), 'logging' => [ 'enabled' => env('QSMS_LOGGING_ENABLED', true), 'path' => storage_path('logs/qsms'), 'level' => env('QSMS_LOG_LEVEL', 'info'), ], ];
- Optionally, publish the configuration file (if you want to customize it further):
php artisan vendor:publish --tag=qsms-config
📱 Features
- Automatic phone number formatting
- Rate limiting protection
- Comprehensive logging
- Error handling
- Message splitting
- Queue support
Phone Number Formats
// All supported formats: $sms->send('255712345678', 'Message'); // International $sms->send('0712345678', 'Message'); // Local with zero $sms->send('712345678', 'Message'); // Local without zero $sms->send('+255712345678', 'Message'); // With plus
Response Handling
$response = $sms->send('255712345678', 'Test'); if ($response['status'] === 'success') { echo "Message sent! ID: " . $response['data']['message_id']; } else { echo "Error: " . $response['message']; }
🧪 Testing
// tests/Feature/SmsTest.php public function test_can_send_sms() { $sms = new SendSMS(); $response = $sms->send('255712345678', 'Test'); $this->assertEquals('success', $response['status']); }
📝 Logging
Logs are stored in storage/logs/qsms/qsms-YYYY-MM-DD.log
{
"timestamp": "2025-04-27 10:30:00",
"level": "info",
"message": "SMS sent",
"context": {
"recipient": "255712345678",
"status": "delivered"
}
}
🔒 Security
- Rate limiting: 10 messages/minute by default
- Secure API token handling
- Phone number validation
- Input sanitization
🤝 Support
📄 License
MIT License. See LICENSE for details.
🔄 Changelog
See CHANGELOG.md for release history.
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-27