hanymigame/laravel-smsru-channel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hanymigame/laravel-smsru-channel

Composer 安装命令:

composer require hanymigame/laravel-smsru-channel

包简介

Sms.ru Notification Channel for laravel.

README 文档

README

Install

composer require hanymigame/laravel-smsru-channel
php artisan vendor:publish --provider="hanymigame\SmsRuChannel\SmsRuServiceProvider"

Add to .env file:

SMS_RU_API_KEY=you_api_key
SMS_RU_SENDER=
SMS_RU_TRANSLIT=0
SMS_RU_TEST=1
SMS_RU_PARTNER_ID=0

Usage

php artisan make:notification SMSNotification

You can use the channel in your via() method inside the notification:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use hanymigame\SmsRuChannel\Messages\SmsRuMessage;
use hanymigame\SmsRuChannel\Channels\SmsRuChannel;

class SMSNotification extends Notification
{
    use Queueable;
    
    public function __construct()
    {
        //
    }
    
    public function via($notifiable)
    {
        return [SmsRuChannel::class];
    }

    public function toSmsRu($notifiable)
    {
        return new SmsRuMessage("Привет! Это тестовое СМС.");
    }

    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

Add in controller, model or command class:

Notification::route('sms_ru_channel', '79301579978')->notify(new SMSNotification());

Edit: app/Providers/EventServiceProvider.php

use Illuminate\Notifications\Events\NotificationSent;
use App\Listeners\ResponseNotification;
use App\Listeners\CheckNotificationStatus;
use Illuminate\Notifications\Events\NotificationSending;

class EventServiceProvider extends ServiceProvider
{

protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        NotificationSending::class => [
            CheckNotificationStatus::class,
        ],
        NotificationSent::class => [
            ResponseNotification::class,
        ],
    ];
    
    ...
    
}

Use command:

php artisan event:generate
php artisan optimize:clear

Add to app/Listeners/ResponseNotification.php

public function handle(NotificationSent $event)
    {
        // $event->channel
        // $event->notifiable
        // $event->notification
        // $event->response
        dump($event->response); // Get response status
    }

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固