androidneha/laravel-msg91
Composer 安装命令:
composer require androidneha/laravel-msg91
包简介
Laravel integration for Msg91 messaging API.
关键字:
README 文档
README
About
This package integrates MSG91's SMS solution nicely with Laravel 5 adding support for Notification & Validator as well.
Registration
Sign up for MSG91 and get the auth key from your account. You can find the auth key from Dashboard > API key after signing in.
Installation
composer require androidneha/laravel-msg91
Laravel < 5.5
Once the package is installed, open your app/config/app.php configuration file and locate the providers key. Add the following line to the end:
Laravel\Msg91\ServiceProvider::class
Next, locate the aliases key and add the following line:
'Msg91' => Laravel\Msg91\Facade::class,
Configuration
Put the credentials and preferences in ENV with the keys MSG91_AUTH_KEY, MSG91_DEFAULT_SENDER, MSG91_DEFAULT_ROUTE, MSG91_DEFAULT_COUNTRY. If you want to customize this, publish the default configuration which will create a config file config/msg91.php.
$ php artisan vendor:publish
Usage
Basic
- Send an SMS to one or more numbers.
<?php $result = Msg91::sms('919999999999', 'Hello there!'); $result = Msg91::sms('919999999999', 'Hello there!', 'TEST12'); $result = Msg91::sms(null, [ ['to' => ['919999999999', '918888888888'], 'message' => 'Hello there!'], ['to' => ['917777777777'], 'message' => 'Come here!'], ], 'TEST12');
- Send OTP to a number.
<?php $result = Msg91::otp('919999999999'); $result = Msg91::otp('919999999999', 'TEST12'); $result = Msg91::otp('919999999999', 'TEST12', '##OTP## is your OTP, Please dont share it with anyone.');
- Verify OTP sent to a number.
<?php $result = Msg91::verify('919999999999', 1290); // returns true or false
Notification
Include msg91 in your notification's channels:
<?php /** * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['msg91']; }
Define the toMsg91 method:
<?php use Laravel\Msg91\Message\Msg91Message; public function toMsg91() { return (new Msg91Message) ->message(__('This is just a test message.')) ->sender('MESG91') // [Optional] - Will pick default sender ID from MSG91_DEFAULT_SENDER or config ->transactional(); // or promotional() [Optional] - Will pick default route from MSG91_DEFAULT_ROUTE or config }
Default routeNotificationForMsg91 method in your notifiable class:
<?php public function routeNotificationForMsg91($notification) { return $this->phone_number; }
Finally send the notification:
<?php $notifiable = /* some class */ $notifiable->notify(new App\Notifications\Msg91TestNotification());
For sending the notification to an arbitrary number, use below syntax:
<?php use Illuminate\Support\Facades\Notification Notification::route('msg91', '919876543210') ->notify(new App\Notifications\Msg91TestNotification());
Validator
You can validate sent OTPs using provided validation rule named msg91_otp as shown below:
<?php use Illuminate\Support\Facades\Validator $data = ['number' => '9876543210', 'otp' => '1234']; $validator = Validator::make($data, [ 'number' => ['required', 'digits:10'], 'otp' => ['required', 'digits:4', 'msg91_otp'], // default key for source number is 'number', you can customize this using 'msg91_otp:key_name' ]); if ($validator->fails()) { // report errors }
License
See LICENSE file.
androidneha/laravel-msg91 适用场景与选型建议
androidneha/laravel-msg91 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.4k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2019 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「laravel」 「otp」 「integration」 「msg91」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 androidneha/laravel-msg91 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 androidneha/laravel-msg91 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 androidneha/laravel-msg91 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
OTP generating package
yii2-sms expand
OTP generating package
Alfabank REST API integration
统计信息
- 总下载量: 12.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-04