fowitech/laravel-sms
Composer 安装命令:
composer require fowitech/laravel-sms
包简介
Persistent sms package for Laravel
README 文档
README
This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.
List of supported gateways:
📦 Install
Via Composer
$ composer require fowitech/laravel-sms
⚡ Configure
Publish the config file
$ php artisan vendor:publish --tag="sms"
In the config file you can set the default driver to use for all your SMS. But you can also change the driver at runtime.
Choose what gateway you would like to use for your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.
// Eg. if you want to use Netgsm. 'driver' => env('SMS_DRIVER', 'netgsm'),
Then fill the credentials for that gateway in the drivers array.
// Eg. for Netgsm. 'netgsm' => [ 'transport' => \Fowitech\Sms\Drivers\Netgsm::class, 'sender' => env('NETGSM_SENDER', ''), 'username' => env('NETGSM_USERNAME', ''), 'password' => env('NETGSM_PASSWORD', ''), 'options' => [ // some options ] ],
🔥 Usage
In your code just use it like this.
# On the top of the file. use Sms; ... # In your Controller. Sms::message("this message")->to(['Number 1', 'Number 2'])->send(); # If you want to use a different driver. Sms::via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send(); # If you want to use options array $options = [ 'send_date' => now()->addHour() ]; Sms::via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send($options); # If you are not a Laravel's facade fan, you can use sms helper: sms()->message("this message")->to(['Number 1', 'Number 2'])->send(); # If you want to use a different driver. sms()->via('gateway')->message("this message")->to(['Number 1', 'Number 2'])->send();
😍 Channel Usage
First you have to create your notification using php artisan make:notification command.
then SmsChannel::class can be used as channel like the below:
namespace App\Notifications; use Illuminate\Bus\Queueable; use Fowitech\Sms\Channels\SmsChannel; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; class InvoicePaid extends Notification { use Queueable; /** * Get the notification channels. * * @param mixed $notifiable * @return array|string */ public function via($notifiable) { return [SmsChannel::class]; } /** * Get the recipients and body of the notification. * * @param mixed $notifiable * @return Builder */ public function toSms($notifiable) { return "Sms message"; } }
Custom Made Driver, How To:
First you have to name your driver in the drivers array and also you can specify any config params you want.
'my_driver' => [ 'transport' => \App\Packages\SMSDriver\MyDriver::class, 'sender' => env('MYDRIVER_SENDER', ''), 'username' => env('MYDRIVER_USERNAME', ''), 'password' => env('MYDRIVER_PASSWORD', ''), 'options' => [ // some options ] ... # Your Config Params here. ]
Ex. You created a class : App\Packages\SMSDriver\MyDriver.
namespace App\Packages\SMSDriver; use Fowitech\Sms\Drivers\Driver; class MyDriver extends Driver { public function __construct($options = []) { $this->sender = config('sms.my_driver.sender'); $this->username = config('sms.my_driver.username'); $this->password = config('sms.my_driver.password'); $this->client = $this->getInstance(); } public function send($options = []) { # Main logic of Sending SMS. } }
🔬 Testing
composer test
fowitech/laravel-sms 适用场景与选型建议
fowitech/laravel-sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 260 次下载、GitHub Stars 达 16, 最近一次更新时间为 2022 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「twilio」 「laravel」 「netgsm」 「iletimerkezi」 「fowitech」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fowitech/laravel-sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fowitech/laravel-sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fowitech/laravel-sms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Componente para integração com serviços de mensageria com APIs externas como Twilio, SendGrid, AWS SES, etc.
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Alfabank REST API integration
统计信息
- 总下载量: 260
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-28