此包使得通过Laravel通知轻松将文件作为传真通过InterFAX发送

v4.0.0 2024-04-02 21:45 UTC

This package is auto-updated.

Last update: 2024-09-02 22:36:52 UTC


README

Latest Version on Packagist Software License Build Status Total Downloads

此包使得使用Laravel 9.x和10.x通过InterFAX发送通知变得简单。

内容

安装

您可以通过composer安装此包

composer require laravel-notification-channels/interfax

服务提供者会自动加载。

设置InterFAX服务

此渠道将使用您的InterFAX用户名和密码。要使用此渠道,请将以下内容添加到您的 config/services.php 文件中

...
'interfax' => [
    'username' => env('INTERFAX_USERNAME'),
    'password' => env('INTERFAX_PASSWORD'),
    'pci'      => env('INTERFAX_PCI', false),
    'interval' => 15,
    'chunk_size' => null,
],
...

这将从 .env 文件中加载您的InterFAX凭据。如果您的请求必须符合PCI-DSS标准,请在 .env 文件中设置 INTERFAX_PCI=true

services.interfax.interval 配置设置是轮询间隔,以秒为单位,用于检查传真状态直到完成。这是可选的,如果为空,则默认为15。间隔的最小值为10秒,因为API中的出站服务每分钟最多有6次请求频率,并且如果轮询频率过高可能会返回错误。

传真有时可能需要超过10分钟才能发送,因此建议配置长时间运行的队列并将传真通知推送到该队列。有关配置长时间运行的队列的更多信息,请参阅这里

services.interfax.chunk_size 配置设置是在InterFAX核心SDK开始分块文件之前的最大文件大小。默认分块大小为1048576。在分块时,会创建一个 \Interfax\Document 对象,但对于符合PCI-DSS标准的API,不存在 /outbound/documents 端点。如果 services.interfax.pci 设置为 true,建议增加分块大小以避免404错误。

用法

要使用此包,您可以在Laravel应用程序中创建一个通知类,例如以下示例中的 DocumentWasSent。确保查阅Laravel的文档 了解此过程。

通过传真发送PDF

<?php
use NotificationChannels\Interfax\InterfaxChannel;
use NotificationChannels\Interfax\InterfaxMessage;
use NotificationChannels\Interfax\Contracts\InterfaxNotificationContract;

class DocumentWasSent extends Notification implements InterfaxNotificationContract
{

    protected $files;

    public function __construct(array $files)
    {
        $this->files = $files;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [InterfaxChannel::class];
    }

    public function toInterfax($notifiable): InterfaxMessage
    {
        return (new InterfaxMessage)
              ->files($this->files);
    }
}

可通知模型需要返回目标传真号码。

public function routeNotificationForInterfax($notification)
{
    if($this->fax)
        return preg_replace('/[^\d]/', '', $this->fax);

    return null;
}

可用的消息方法

file(string $file) : 接受单个文件的完整路径(支持文件类型的完整列表在这里找到)。
files(array $array) : 接受文件路径数组。如果覆盖默认的chunk_size配置并使用数组中的 \Interfax\File 对象,则使用 \NotificationChannels\Interfax\InterfaxFile 代替以自动设置文件的chunk_size在初始化时。
stream(Filestream $stream, string $name) : 接受文件流。
addMetadata(array $data): 添加用于错误记录目的的元数据。

变更日志

请参阅 CHANGELOG 了解最近的变化。

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过craig.spivack@ivinteractive.com 发送电子邮件,而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

致谢

许可证

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