m-shule/africastalking

AfricasTalking 通知驱动程序,适用于Laravel 5.3+

v2.0.3 2020-10-14 15:24 UTC

This package is auto-updated.

Last update: 2024-09-15 00:44:06 UTC


README

此包使得使用AfricasTalking向Laravel 5.3+发送通知变得简单。

内容

要求

安装

您可以通过composer安装此包

composer require m-shule/africastalking

对于Laravel 5.4或更低版本,您必须将服务提供者添加到您的配置中

// config/app.php
'providers' => [
    ...
    MShule\AfricasTalking\AfricasTalkingServiceProvider::class,
],

设置AfricasTalking服务

将环境变量添加到您的 config/services.php

// config/services.php
...
'africastalking' => [
    'api_key' => env('AFRICASTALKING_API_KEY'),
    'username' => env('AFRICASTALKING_USERNAME'),
    'from' => env('AFRICASTALKING_FROM'),
],
...

将您的AfricasTalking API密钥、用户名和发送者号码/短码添加到您的 .env

// .env
...
AFRICASTALKING_API_KEY=
AFRICASTALKING_USERNAME=
AFRICASTALKING_FROM=
...

from变量是可选的。

用法

现在您可以在通知内的 via() 方法中使用该通道

<?php

// app/Notifications/VpsServerOrdered.php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use MShule\AfricasTalking\AfricasTalkingChannel;
use MShule\AfricasTalking\AfricasTalkingMessage;

class VpsServerOrdered extends Notification
{
    public function via($notifiable)
    {
        return [AfricasTalkingChannel::class];
    }

    public function toAfricasTalking($notifiable)
    {
    	return (new AfricasTalkingMessage())->content("Your service was ordered!");
    }
}

此外,您还可以通过

return (new AfricasTalkingMessage())->content("Your service was ordered!")->from('60606');

您还可以向未存储为“用户”的人发送通知

...
use App\Notifications\VpsServerOrdered;
use Illuminate\Notifications\Notification;
...

Notification::route('africastalking', '+254712345678')->notify(new VpsServerOrdered());

...

变更日志

有关最近更改的更多信息,请参阅变更日志

安全

如果您发现任何安全相关的问题,请通过电子邮件hello@m-shule.com报告,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅贡献

鸣谢

许可

MIT许可证(MIT)。有关更多信息,请参阅许可证文件