topcu/toplusmslaravel

关于此包的最新版本(v1.0.2)没有可用的许可信息。

toplusmsapi.com 的 Laravel 通知

v1.0.2 2017-04-25 08:03 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:57:56 UTC


README

介绍

这是一个简单的 Laravel 通知通道。

安装

首先,您需要使用 Composer 需求此包

composer require topcu/toplusmslaravel

然后,从您的命令行运行 composer update

然后,通过添加服务提供者条目来更新 config/app.php

'providers' => [
	// ...
    Topcu\TopluSms\TopluSmsProvider::class,
];

然后,通过添加您的 toplusms 凭据来更新 config/services.php

return [
   // ...
	,
        'toplusms' => [
            'username' => env('TOPLUSMS_USERNAME'),
            'password' => env('TOPLUSMS_PASSWORD'),
            'from' => env('TOPLUSMS_FROM', null), // Can be ovverdiden with $message->from() 
        ]
    // ...
];

使用方法

路由短信通知

为了发送短信消息,您需要为每个可通知实体指定接收者。例如,在 app/user.php

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

发送通知

通过方法

在您的通知类中,您可以定义通道为

    // ...
    public function via($notifiable)
    {
        return ['sms'];
    }
    // ...

短信方法

您还需要定义 toSms 方法。您可以

  1. 发送一个简单的字符串作为
    // ...
    public function toSms($notifiable)
    {
        return "Hello World!";
    }
    // ...
  1. 或定义一个来自(发送者)以覆盖配置
    // ...
    public function toSms($notifiable)
    {
       $message = new SmsMessage("Hello World");
       $message->from("5xxxxxxxxx");
       return $message;
    }
    // ...