isend/laravel
Composer 安装命令:
composer require isend/laravel
包简介
Laravel SDK for iSend SMS API v3
README 文档
README
A Laravel package for sending SMS messages using the iSend SMS API v3. Simple to use and easy to set up.
Key Features
- SMS messaging with single/multiple recipients
- Message scheduling and delivery tracking
- Campaign management
- Error handling with detailed diagnostics
- Interactive CLI setup wizard
Requirements
- PHP 8.2 or higher
- Laravel 11.x or 12.x
- Guzzle HTTP client
- Valid iSend SMS API credentials
Installation
You can install the package via Composer:
composer require isend/laravel
The package will automatically register itself using Laravel's package discovery.
Configuration
Interactive Setup (Recommended)
The easiest way to set up the package is by using the interactive setup command:
php artisan isend:setup
This command will set up your API credentials and publish the config file in one step.
Or, Manual Configuration
Alternatively, you can manually publish the configuration file:
php artisan vendor:publish --tag="isend-config"
This will create a config/isend.php file with comprehensive configuration options.
Then, add these environment variables to your .env file:
ISEND_API_TOKEN=your-api-token
ISEND_DEFAULT_SENDER_ID=your-sender-id
Optional Environment Variables
You can customize the service with these additional variables:
ISEND_BASE_URL=https://isend.com.ly
ISEND_API_VERSION_PATH=/api/v3
Basic Usage
Sending a Simple SMS
use ISend\SMS\Facades\ISend; // Fluent interface ISend::to('218929000834') ->message('Your verification code is 1234') ->send(); // Get the SMS ID for tracking $smsId = ISend::to('218929000834') ->message('Your verification code is 1234') ->send() ->getId(); // Static helper method ISend::sendSms('218929000834', 'Your verification code is 1234');
Multiple Recipients
// Send the same message to multiple recipients ISend::to(['218929000834', '218929000836', '218929000837']) ->message('Important announcement for all users') ->send(); // Or as a comma-separated string ISend::to('218929000834,218929000836,218929000837') ->message('Important announcement for all users') ->send();
Custom Sender ID
ISend::to('218929000834') ->from('MyApp') // Override the default sender ID ->message('Your verification code is 1234') ->send();
Scheduled Messages
// Schedule a message for future delivery ISend::to('218929000834') ->message('Reminder: Your appointment is tomorrow') ->scheduleAt('2025-12-31 09:00:00') // Format: Y-m-d H:i ->send();
DLT Template ID (for regulatory compliance)
// For regions requiring DLT template registration ISend::to('218929000834') ->message('Your OTP is 1234') ->dltTemplateId('template-123') ->send();
Advanced Features
Checking Message Status
// Get the status of a sent message using its ID $status = ISend::getStatus('sms-uid-123456'); // Example response structure [ 'status' => 'success', 'data' => [ 'uid' => 'sms-uid-123456', 'status' => 'delivered', 'sent_at' => '2025-01-01 12:00:00', 'delivered_at' => '2025-01-01 12:00:05', // Additional status details... ] ]
Listing Messages
// Get a list of all sent messages $messages = ISend::listMessages();
Campaign Management
// Send a campaign to a contact list $campaign = ISend::sendCampaign( 'contact-list-123', 'Special offer for our valued customers!', 'Marketing', // Optional custom sender ID '2025-02-15 08:00:00' // Optional schedule time ); // Send to multiple contact lists $campaign = ISend::sendCampaign( ['list-123', 'list-456'], 'Special offer for all our customers!' );
Account Management
// Get profile information $profile = ISend::getProfile(); // Check account balance $balance = ISend::checkBalance(); // Get registered sender IDs $senderIds = ISend::getSenderIds(); // Get transaction history $transactions = ISend::getTransactions();
Exception Handling
The package throws ISendException with detailed error information:
use ISend\SMS\Exceptions\ISendException; try { ISend::to('invalid-number') ->message('Test message') ->send(); } catch (ISendException $e) { // Basic error information $message = $e->getMessage(); $statusCode = $e->getStatusCode(); // Detailed error data $responseData = $e->getResponseData(); // Full API response $requestData = $e->getRequestData(); // The request that caused the error // Error type helpers if ($e->isAuthenticationError()) { // Handle 401 errors (invalid API token) } if ($e->isValidationError()) { // Handle 422 errors (invalid parameters) } if ($e->isServerError()) { // Handle 5xx errors (server issues) } // Get complete error details as array $errorDetails = $e->toArray(); // Log the error or handle as needed... }
Debugging
For debugging purposes, you can access the last API response:
$response = ISend::to('218929000834') ->message('Test message') ->send() ->getLastResponse();
Testing
The package includes a comprehensive test suite:
composer test
Laravel Version Compatibility
| Laravel Version | Package Version |
|---|---|
| 11.x | 1.x |
| 12.x | 1.x |
Security
If you discover any security issues, please email soliman.benhalim@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
isend/laravel 适用场景与选型建议
isend/laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 836 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 05 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sms」 「communication」 「messaging」 「notification」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 isend/laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 isend/laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 isend/laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dispatcher to handle e-mail and instant notifications.
Package to publish/consume domain events messages from Laravel apps
A PSR-7 compatible library for making CRUD API endpoints
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Manage Node resources from PHP
Extensible library for building notifications and sending them via different delivery channels.
统计信息
- 总下载量: 836
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-03