misaf/laravel-sms-gateway
最新稳定版本:v1.0.1
Composer 安装命令:
composer require misaf/laravel-sms-gateway
包简介
Supercharge your Laravel applications with our seamless SMS Gateway integration!
README 文档
README
A flexible and easy-to-use SMS gateway package for Laravel applications. This package provides a unified interface for sending SMS messages through multiple providers, making it simple to switch between different SMS services or use multiple providers simultaneously.
Features
- 🚀 Multiple Driver Support: Built-in support for Ghasedak and Sunway SMS providers
- 🔌 Extensible Architecture: Easy to add custom SMS drivers
- 🎯 Laravel Integration: Seamless integration with Laravel's service container
- 📝 Facade Support: Clean and intuitive API using Laravel facades
- ⚙️ Configuration Management: Environment-based configuration
- 🔒 Type Safe: Built with strict types and modern PHP practices
Requirements
- PHP >= 8.2
- Laravel >= 10.0
Installation
You can install the package via Composer:
composer require misaf/laravel-sms-gateway
Configuration
Publish Configuration
Publish the configuration file to your config directory:
php artisan vendor:publish --tag=laravel-sms-gateway-config
Or manually publish the config file:
php artisan vendor:publish --provider="Misaf\LaravelSmsGateway\SmsGatewayServiceProvider"
Environment Variables
Add the following environment variables to your .env file:
# Default SMS Gateway Driver SMS_GATEWAY_DRIVER=ghasedak # Ghasedak Configuration SMS_GATEWAY_GHASEDAK_APIKEY=your-api-key SMS_GATEWAY_GHASEDAK_LINENUMBER=your-line-number # Sunway Configuration SMS_GATEWAY_SUNWAY_GATEWAY=https://sms.sunwaysms.com/smsws/HttpService.ashx SMS_GATEWAY_SUNWAY_USERNAME=your-username SMS_GATEWAY_SUNWAY_PASSWORD=your-password SMS_GATEWAY_SUNWAY_SPECIALNUMBER=your-special-number
Usage
Using the Facade
use Misaf\LaravelSmsGateway\Facade\SmsGateway; // Send SMS using the default driver SmsGateway::driver()->send() ->get('HttpService.ashx', [ 'method' => 'SendSMS', 'mobile' => '09123456789', 'message' => 'Hello, World!' ]); // Use a specific driver SmsGateway::driver('sunway')->send() ->get('HttpService.ashx', [ 'method' => 'SendSMS', 'mobile' => '09123456789', 'message' => 'Hello, World!' ]);
Using Dependency Injection
use Misaf\LaravelSmsGateway\SmsGatewayManager; class SmsController extends Controller { public function __construct( private SmsGatewayManager $smsGateway ) {} public function sendSms() { $this->smsGateway->driver()->send() ->get('HttpService.ashx', [ 'method' => 'SendSMS', 'mobile' => '09123456789', 'message' => 'Hello, World!' ]); } }
Using the Service Container
$smsGateway = app('sms-gateway'); $smsGateway->driver('ghasedak')->send() ->get('HttpService.ashx', [ 'method' => 'SendSMS', 'mobile' => '09123456789', 'message' => 'Hello, World!' ]);
Available Drivers
Ghasedak
The Ghasedak driver is configured with:
apiKey: Your Ghasedak API keylinenumber: Your Ghasedak line number
Sunway
The Sunway driver is configured with:
gateway: The Sunway SMS gateway URLusername: Your Sunway usernamepassword: Your Sunway passwordspecial_number: Your Sunway special number
Creating Custom Drivers
To create a custom driver, implement the SmsGatewayHandlerInterface:
<?php namespace App\SmsGateways; use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Facades\Http; use Misaf\LaravelSmsGateway\Interfaces\SmsGatewayHandlerInterface; class CustomDriver implements SmsGatewayHandlerInterface { public function send(): PendingRequest { return Http::withHeaders([ 'Authorization' => 'Bearer ' . config('sms-gateway.drivers.custom.api_key'), ])->baseUrl('https://api.example.com') ->timeout(10) ->connectTimeout(5); } }
Then register your driver in the SmsGatewayManager:
protected function createCustomDriver() { return new CustomDriver(); }
Testing
Run the test suite:
composer test
Code Style
This package uses Laravel Pint for code style. Format your code:
composer pint
License
This package is open-sourced software licensed under the MIT license.
Support
- Issues: GitHub Issues
- Source: GitHub Repository
Author
Ehsan Mahmoodi
- Email: misaf.1990@gmail.com
Made with ❤️ for the Laravel community
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-27