承接 zing/laravel-sms 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zing/laravel-sms

最新稳定版本:6.6.0

Composer 安装命令:

composer require zing/laravel-sms

包简介

Provides sms notification channel for Laravel.

README 文档

README

Tests Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality StyleCI Shield Code Climate FOSSA Status

Laravel Sms is used to notify via sms and send a message.

Thanks

Many thanks to:

  • JetBrains for the excellent PhpStorm IDE and providing me with an open source license to speed up the project development.

    JetBrains

Requirements

Installation

Composer

Execute the following command to get the latest version of the package:

composer require zing/laravel-sms

Laravel

Publish Configuration

php artisan vendor:publish --provider "Zing\LaravelSms\SmsServiceProvider"

Add Connections

This package based on overtrue/easy-sms, driver is the gateway.

Usage

Channel

Create a Notification

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class Verification extends Notification implements ShouldQueue
{
    use Queueable;

    protected $code;

    /**
     * Verification constructor.
     *
     * @param $code
     */
    public function __construct($code)
    {
        $this->code = $code;
    }

    public function via()
    {
        return ['sms'];
    }

    public function toSms($notifiable)
    {
        return "验证码 {$this->code},您正在进行身份验证,打死也不要告诉别人哦!";
    }
}

Add notification route for sms to your notifiable

use Illuminate\Notifications\Notifiable;

class User
{
    use Notifiable;

    public function routeNotificationForSms($notification)
    {
        return $this->phone;
    }
}

Send notification

use Illuminate\Support\Facades\Notification;

$user = new User();
// use Notifiable Trait
$user->notify(new Verification('1111'));
// use Notification Facade
Notification::send($user, new Verification('1111'));

Send to anonymous notifiable

use Illuminate\Support\Facades\Notification;
use Zing\LaravelSms\SmsNumber;
use Zing\LaravelSms\Channels\SmsChannel;

// use channel class name
Notification::route(SmsChannel::class, new SmsNumber(18188888888, 86))->notify(new Verification('1111'));
// use channel alias
Notification::route('sms', new SmsNumber(18188888888, 86))->notify(new Verification('1111'));

Facade

Send Message

use Zing\LaravelSms\Facades\Sms;

// use default connection
Sms::send(18188888888, 'test message.');
// use specific connection
Sms::connection('null')->send(18188888888, 'test message.');
// or
Sms::via('null')->send(18188888888, 'test message.');

Specific usage

Use specific connection for notification

NOTE: Only support for Zing\LaravelSms\SmsMessage

use Zing\LaravelSms\SmsMessage;

public function toSms($notifiable)
{
    return (new SmsMessage())->onConnection('log');
}

Make PhoneNumber notifiable

NOTE: Only support for Zing\LaravelSms\SmsNumber

use Zing\LaravelSms\SmsNumber;

(new SmsNumber(18188888888))->notify(new Verification('1111'));

License

Laravel Sms is open-sourced software licensed under the MIT license.

FOSSA Status

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-10