rongself/laravel-luosimao-sms

luosimao Api for laravel 5.4.*

v0.0.3 2017-08-18 07:44 UTC

This package is not auto-updated.

Last update: 2024-05-12 02:10:30 UTC


README

螺丝帽 短信 Channel for laravel 5.4.*

安装

composer require 'rongself/laravel-luosimao-sms'

配置

  • 编辑config/app.php注册provider:
'providers' => [
        Rongself\Luosimao\Providers\LuosimaoSmsProvider::class
],
  • 生成配置文件
php artisan vendor:publish 

编辑config/luosimao-sms.php填入app_key

  • 通知模板via中使用Channel
<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Rongself\Luosimao\Channels\SmsChannel;

/**
 * Class ChargeResult
 * @package App\Notifications
 */
class ChargeResult extends Notification 
{

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [SmsChannel::class];
    }
    
    //定义短信内容
    public function toSmsMessage($notifiable)
    {
        return '验证码:19272【铁壳测试】';
    }
}
  • 自定义电话字段
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;
    
    //添加getPhone方法返回相应字段
    public function getPhone()
    {
        return $this->Tel;
    }

}
  • 发送
<?php
//发送通知消息
$user = User::find(1);
$message = new ChargeResult();
$user->notify($message);

关于通知消息使用详情参考 laravel官方文档