bodyansky/plivo

Laravel 的 Plivo SMS 集成

0.0.4 2022-04-14 08:54 UTC

This package is auto-updated.

Last update: 2024-09-14 15:42:35 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License
Laravel 的 Plivo SMS 集成

安装

此包需要 PHP 7.4+,并包含 Laravel 7 Service Provider 和 Facade。

通过 composer 安装时,请将包包含在您的 composer.json 文件中。

"bodyansky/plivo": "1.1.0"

运行 composer installcomposer update 以下载依赖项,或者您可以运行 composer require bodyansky/plivo

刷新自动加载器

在此阶段,一些用户可能需要运行命令 composer dump-autoload。或者,您可以运行 php artisan optimize,这应该包括 dump-autoload 命令。

Laravel 7+ 集成

要使用此包与 Laravel 5,首先将 Messaging 服务提供者添加到 app/config/app.php 中的服务提供者列表中。

'providers' => [
  Bodyansky\Plivo\MessagingServiceProvider::class
];

Messaging Facade 添加到您的别名单组中。

'aliases' => [
  'Messaging' => Bodyansky\Plivo\Facades\Messaging::class,
];

使用以下命令发布配置和迁移文件:

php artisan vendor:publish --provider="Bodyansky\Plivo\MessagingServiceProvider"

要访问 Plivo/Messaging,您可以使用 Facade 或 Messaging 实例已绑定到 IOC 容器,然后通过其合同进行依赖注入。

Messaging::get('foo');

public function __construct(Bodyansky\Plivo\Contracts\Services\Messaging $messaging)
{
    $this->messaging = $messaging;
}

配置文件

发布配置文件后,您将在 config 文件夹中找到一个 Plivo.php 文件。您应该查看这些设置,并在必要时进行更新。

环境变量

您需要将以下内容添加到您的 .env 文件中,并使用您自己的设置更新这些内容

PLIVO_AUTH_ID=<auth_id>
PLIVO_AUTH_TOKEN=<auth_token>
PLIVO_SOURCE_NUMBER=<default_sms_number>

示例用法

use Bodyansky\Plivo\Contracts\Services\Messaging;
    
public function sendMessage(Messaging $messaging) 
{
    $msg = $messaging->msg('Hello World!')->to('0123456789')->sendMessage(); 
}

// Or you can simply use the helper function
   
text('+44123456789', 'Just reminding you to attend the Dentist at 3.30pm');

Text takes three arguments, to, message and optionally from.

// If text is already defined as a function in your application you can use
text_message($to, $message, $from); // or
plivo_send_text($to, $message, $from);