pishehgostar/exchange-melipayamak

此软件包最新版本(v1.0.0)没有可用的许可信息。

v1.0.0 2024-02-04 14:04 UTC

This package is auto-updated.

Last update: 2024-09-04 15:58:08 UTC


README

此软件包使用 Laravel 9.x 使通过 Melipayamak 发送通知变得简单,Melipayamak 是一个Melipayamak 服务的集成。

安装

此软件包可以通过 Composer 安装。

composer require pishehgostar/exchange-melipayamak

设置 Melipayamak 服务

在 services.php 配置文件中添加您的 melipayamak 服务信息。

return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third party services such
    | as Mailgun, Postmark, AWS and more. This file provides the de facto
    | location for this type of information, allowing packages to have
    | a conventional file to locate the various service credentials.
    |
    
    // ...
    
    'melipayamak'=>[
        'username'=>'###',
        'password'=>'###',
        'from'=>'###',
    ]
    
];

用法

在每个您希望通过 Melipayamak 通知的模型中,您必须添加一个通道 ID 属性,并通过 routeNotificationForMelipayamak 方法访问该属性。

class YourModel extends Eloquent
{
    use Notifiable;

    public function routeNotificationForMelipayamak(Notification $notification): array|string
    {
        return $this->mobile;
    }
}

现在您可以在 via 方法中告诉 Laravel 将通知发送到 melipayamak 通道。

class InvoicePaidNotification extends Notification
{
    public function via(object $notifiable): array
    {
        return ['melipayamak'];
    }
    
    // send sms using patterns
    public function toMelipayamak(object $notifiable): MelipayamakSmsMessage
    {
        $pattern_code = '######';
        $pattern_parameters = ['first','second'];
        return (new MelipayamakSmsMessage)
            ->pattern($pattern_code,$pattern_parameters);
    }
    
    // send simple sms
    public function toMelipayamak(object $notifiable): MelipayamakSmsMessage
    {
        return (new MelipayamakSmsMessage)
            ->simple('salam');
    }
}