zareshahi/sms
Composer 安装命令:
composer require zareshahi/sms
包简介
Laravel SMS Gateway Integration Package
关键字:
README 文档
README
This is a Laravel Package for SMS Gateway Integration. Now Sending SMS is easy.
List of supported gateways:
-
Others are under way.
📦 Install
Via Composer
$ composer require tzsk/sms
⚡ Configure
Publish the config file
$ php artisan sms:publish
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 SNS. 'default' => 'sns',
Then fill the credentials for that gateway in the drivers array.
// Eg. for SNS. 'drivers' => [ 'sns' => [ // Fill all the credentials here. 'key' => 'Your AWS SNS Access Key', 'secret' => 'Your AWS SNS Secret Key', 'region' => 'Your AWS SNS Region', 'sender' => 'Your AWS SNS Sender ID', 'type' => 'Tansactional', // Or: 'Promotional' ], ... ]
Textlocal Configuration:
Textlocal is added by default. You just have to change the creadentials in the textlocal driver section.
AWS SNS Configuration:
In case you want to use AWS SNS. Then you have to pull a composer library first.
composer require aws/aws-sdk-php
Clockwork Configuration:
In case you want to use Clockwork. Then you have to pull a composer library first.
composer require mediaburst/clockworksms
Twilio Configuration:
In case you want to use Twilio. Then you have to pull a composer library first.
composer require twilio/sdk
Then you just have to change the creadentials in the twilio driver section.
Melipayamak Configuration:
In case you want to use Melipayamak. Then you have to pull a composer library first.
composer require melipayamak/php
Kavenegar Configuration:
In case you want to use Kavenegar. Then you have to pull a composer library first.
composer require kavenegar/php
SMS Gateway Me Configuration:
In case you want to use SMS Gateway Me. Then you have to pull a composer library first.
composer require smsgatewayme/client
🔥 Usage
In your code just use it like this.
# On the top of the file. use Tzsk\Sms\Facades\Sms; //// # In your Controller. Sms::send("this message", function($sms) { $sms->to(['Number 1', 'Number 2']); # The numbers to send to. }); # OR... Sms::send("this message")->to(['Number 1', 'Number 2'])->dispatch(); # If you want to use a different driver. Sms::via('gateway')->send("this message", function($sms) { $sms->to(['Number 1', 'Number 2']); }); # OR... Sms::via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch(); # Here gateway is explicit : 'twilio' or 'textlocal' or any other driver in the config. # The numbers can be a single string as well. # If you are not a Laravel's facade fan, you can use sms helper: sms()->send("this message", function($sms) { $sms->to(['Number 1', 'Number 2']); # The numbers to send to. }); sms()->send("this message")->to(['Number 1', 'Number 2'])->dispatch(); sms()->via('gateway')->send("this message", function($sms) { $sms->to(['Number 1', 'Number 2']); }); sms()->via('gateway')->send("this message")->to(['Number 1', 'Number 2'])->dispatch();
😍 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 Tzsk\Sms\Builder; use Illuminate\Bus\Queueable; use Tzsk\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 repicients and body of the notification. * * @param mixed $notifiable * @return Builder */ public function toSms($notifiable) { return (new Builder)->via('gateway') # via() is Optional ->send('this message') ->to('some number'); } }
Tip: You can use the same Builder Instance in the send method.
$builder = (new Builder)->via('gateway') # via() is Optional ->send('this message') ->to('some number'); Sms::send($builder); # OR... $builder = (new Builder)->send('this message') ->to(['some number']); Sms::via('gateway')->send($builder);
Custom Made Driver, How To:
First you have to name your driver in the drivers array ,and also specify any config params you want.
'drivers' => [ 'textlocal' => [...], 'twilio' => [...], 'my_driver' => [ ... # Your Config Params here. ] ]
Now you have to create a Driver Map Class that will be used to send the SMS. In your driver, You just have to
extend Tzsk\Sms\Contracts\Driver.
Ex. You created a class : App\Packages\SMSDriver\MyDriver.
namespace App\Packages\SMSDriver; use Tzsk\Sms\Contracts\Driver; class MyDriver extends Driver { /** * You Should implement these methods: * * 1. boot() -> (optional) Initialize any variable or configuration that you need. * 2. send() -> Main method to send messages. * * Note: settings array will be automatically assigned in Driver class' constructor. * * Example Given below: */ /** * @var mixed */ protected $client; protected function boot() : void { $this->client = new Client(); # Guzzle Client for example. } /** * @return object Ex.: (object) ['status' => true, 'data' => 'Client Response Data']; */ public function send() { $this->recipients; # Array of Recipients. $this->body; # SMS Body. # Main logic of Sending SMS. ... } }
Once you crate that class you have to specify it in the sms.php Config file map section.
'map' => [ ... 'my_driver' => App\Packages\SMSDriver\MyDriver::class, ]
Note:- You have to make sure that the key of the map array is identical to the key of the drivers array.
🔬 Testing
composer test
📅 Changelog
Please see CHANGELOG for more information on what has changed recently.
❤️ Contributing
Please see CONTRIBUTING for details.
🔒 Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
👑 Credits
👮♂️ License
The MIT License (MIT). Please see License File for more information.
zareshahi/sms 适用场景与选型建议
zareshahi/sms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「tzsk」 「laravel sms gateway」 「laravel textlocal」 「laravel twilio」 「laravel link mobility」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zareshahi/sms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zareshahi/sms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zareshahi/sms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generate Image Collage with Laravel
Laravel API Request Response Encryption
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Pushwoosh for Laravel
yii2-sms expand
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-24