gabeta/laravel-custom-sms-channels
Composer 安装命令:
composer require gabeta/laravel-custom-sms-channels
包简介
Channels SMS notification for providers not supported by laravel by default.
README 文档
README
Laravel notification channels package for a few SMS providers. The specificity of this package is that you can combine several SMS sending services (supported by the package) in the same project without adding additional code. Have you always wanted to receive your SMS locally? preview them make consequent adjustments? We also offer you this functionality.
Installation
You can install the package via composer:
composer require gabeta/laravel-custom-sms-channels
You can publish the config file with:
php artisan vendor:publish --provider="Gabeta\CustomSmsChannels\CustomSmsChannelsServiceProvider" --tag="config"
Setting up your SMS provider
'default' => env('CUSTOM_SMS_CHANNEL', 'sms_log'), 'preview' => [ 'enable' => env('ENABLE_SMS_PREVIEW', true), 'domain' => null, 'path' => '/customs-sms-dashboard', ], 'providers' => [ 'sms_log' => [ 'config' => [ 'driver' => 'single', 'path' => storage_path('logs/custom-sms.log'), 'level' => 'info', ], ], 'infobip' => [ 'send_from' => env('INFOBIP_SEND_FROM'), 'api_host' => env('INFOBIP_API_HOST'), 'api_key_prefix' => env('INFOBIP_API_KEY_PREFIX'), 'api_key' => env('INFOBIP_API_KEY'), ] .... ]
Usage
Now you can use the channel in your via() method inside the notification:
use Illuminate\Notifications\Notification; class WelcomeNotification extends Notification { public function via($notifiable) { return ['customsms']; } public function toCustomSms($notifiable) { return "Hello Laravel Community from Ivory Coast (Côte D'ivoire)"; } }
The customsms channel will automatically use the provider you have defined
by default in your configuration file. It should be noted that a channel
will be created for each provider supported by the package.
See the list of channels supported.
In order to let your Notification know which user(s) phone number you are targeting,
add the routeNotificationForCustomSms method to your Notifiable model.
The routeNotificationForCustomSms method must return an instance of
Gabeta\CustomSmsChannels\PhoneNumber.
use Gabeta\CustomSmsChannels\Facades\PhoneNumber; public function routeNotificationForCustomSms() { return PhoneNumber::setDialCode($this->dial_code) ->setPhone($this->phone); }
In the example above (the dial code and number are stored in separate fields)
we return an instance of Gabeta\CustomSmsChannels\PhoneNumber while setting
the dial_code without any prefix (+ or 00) and the phone number.
There are providers that use the dial code and number without a prefix to send SMS
others use the + or 00 prefix. The system will take care of the formatting according to
of each provider. If the number and dial code are stored in the same field you can
set with method.
use Gabeta\CustomSmsChannels\Facades\PhoneNumber; public function routeNotificationForCustomSms() { return PhoneNumber::setRouteNotification($this->full_phone_number); }
We advise you to provide the telephone number without the prefix. As mentioned above top the system will take care of the prefixing according to the provider.
Preview SMS Localy
To preview your SMS locally use the sms_log driver activate the preview
in your config file.
Publish dashboard assets:
php artisan vendor:publish --provider="Gabeta\CustomSmsChannels\CustomSmsChannelsServiceProvider" --tag="public"
Go to: http://YOUR_HOST/customs-sms-dashboard for preview your SMS.
Provider supporter
| Providers | channel | via method | route notification method |
|---|---|---|---|
| log ✅ | log | toLogSms | routeNotificationForLogSms |
| infobip ✅ | infobip | toInfobip | routeNotificationForInfobip |
| twilio ✅ | twilio | toTwilio | routeNotificationForTwilio |
You could use via or route notification method if you want behavior
channel-specific. The package tries to find the via method and the route notification method
specific to its provider if it does not find it it will call the routeNotificationForCustomSms functions
and toCustomSms.
Would you like to combine a notification channel package such as Laravel vonage package with our package ? Yes it is possible. you must first install their package then add their channel with null value in the supported provider in the config file.
Example:
'providers' => [ 'vonage' => null ]
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.
gabeta/laravel-custom-sms-channels 适用场景与选型建议
gabeta/laravel-custom-sms-channels 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 8, 最近一次更新时间为 2022 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「notification」 「laravel」 「Infobip」 「laravel-custom-sms-channels」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gabeta/laravel-custom-sms-channels 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gabeta/laravel-custom-sms-channels 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gabeta/laravel-custom-sms-channels 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Apple Push Notification & Feedback Provider
Throttle notifications on a per-channel basis
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Simple javascript toast notifications
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-24
