craftsys/msg91-laravel-notification-channel
Composer 安装命令:
composer require craftsys/msg91-laravel-notification-channel
包简介
Laravel notification channel for MSG91 apis.
README 文档
README
Laravel notification channel for Msg91 API (wrapper around Laravel Msg91 Client)
Table of Contents
Installation
prerequisite
- php^7.1
- laravel^5|^6|^7|^8|^9|^10
The package is tested for 5.8+,^6.0,^7.0,^8.0,^9.0,^10.0 only. If you find any bugs for laravel (5.0< >5.8), please file an issue.
composer require craftsys/msg91-laravel-notification-channel
If you just want to integrate Msg91 api in Laravel without notification channel, please use Msg91 Laravel instead.
Configuration
Next, you will need to add a few configuration options to your config/services.php configuration file. You may copy the example configuration below to get started:
// along with other services 'msg91' => [ 'key' => env("MSG91_KEY") ]
All available configuration can be found at msg91-php client's configuration page
Usage
If a notification supports being sent as an SMS, you should define a toMsg91 method on the notification class. This method will receive a $notifiable entity and should return a Craftsys\Notifications\Messages\Msg91SMS or Craftsys\Notifications\Messages\Msg91OTP instance based on your need to sending message or sending an OTP.
NOTE: Phone number must be in international format i.e. it must include the country code.
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use Craftsys\Notifications\Messages\Msg91SMS class OrderPicked extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { // add "msg91" channel to the channels array return ['msg91']; } /** * Get the Msg91 / SMS representation of the notification. * * @param mixed $notifiable * @return \Craftsys\Notifications\Messages\Msg91SMS */ public function toMsg91($notifiable) { return (new Msg91SMS) ->flow('your_flow_id_here') // you can also set variable's values for your flow template // assuming you have ##order_id## variable in the flow ->variable('order_id', $notifiable->latestOrder->id); } }
SMS
// your Notification public function toMsg91($notifiable) { return (new \Craftsys\Notifications\Messages\Msg91SMS) ->flow("your_flow_id"); } // with variables public function toMsg91($notifiable) { return (new \Craftsys\Notifications\Messages\Msg91SMS) ->flow("your_flow_id") ->variable('name', $notifiable->name) ->variable('status', "Overdue"); }
OTP
// your Notification public function toMsg91($notifiable) { return (new \Craftsys\Notifications\Messages\Msg91OTP) ->from('12123'); // ->otp(12123) // set a custom otp // ->resend() // if this is a resend otp notification }
Verify OTP
This package include the Laravel Msg91 Client, so you can use all the api provided by that package like verify an OTP, sending otp without using notification channel etc.
You can access the client using Msg91 facade as follows:
$otp_to_verify = 112312; Msg91::otp($otp_to_verify)->to(919999999998)->verify();
Routing SMS Notification
When sending notifications via the msg91 channel, the notification system will automatically look for a
phone_number attribute on the notifiable entity. If you would like to customize the phone number the notification
is delivered to, define a routeNotificationForMsg91 method on the entity as suggested on laravel
docs.
class User { use Notifiable; /** * Route notifications for the Msg91 channel. * * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForMsg91 ($notification) { return $this->phone; } }
You can also set the recipient(s) when composing your message in the toMsg91 method of your notification as
follows:
public function toMsg91($notifiable) { return (new \Craftsys\Notifications\Messages\Msg91SMS) ->to(91992123123) // you can also pass an array for bulk notifications ->flow('your_flow_id'); }
Advanced Usage
These messages Msg91SMS and Msg91OTP extend \Craftsys\Msg91\SMS\Options and \Craftsys\Msg91\OTP\Options, so all configuration methods are available when crafting your notification message. These are all optional and you can use them in any order. e.g.
public function toMsg91($notifiable) { return (new \Craftsys\Notifications\Messages\Msg91OTP) ->digits(6) // set the digits in otp message ->expiresInMinutes(1) // change the expiry time ->from("SNCBD"); // set a custom sender id }
Related
Acknowledgements
craftsys/msg91-laravel-notification-channel 适用场景与选型建议
craftsys/msg91-laravel-notification-channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56.88k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sms」 「laravel」 「msg91」 「notification-channel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 craftsys/msg91-laravel-notification-channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 craftsys/msg91-laravel-notification-channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 craftsys/msg91-laravel-notification-channel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
yii2-sms expand
Alfabank REST API integration
A fork of simplesoftwareio/simple-sms with Verimor driver.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 56.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-21