midnite81/plivo

此包已被废弃且不再维护。未建议替代包。

Laravel 的 Plivo SMS 集成

v0.1.10 2017-12-24 15:13 UTC

This package is auto-updated.

Last update: 2022-02-17 21:24:35 UTC


README

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

项目已归档

自创建此包以来,Plivo 更新了他们的自有 API 包,该包非常全面。因此,我决定归档此项目,因为我不再对其进行任何当前开发。

安装

此包需要 PHP 5.6+,并包含 Laravel 5 服务提供者和外观。

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

"midnite81/plivo": "0.1.*"

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

刷新自动加载器

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

Laravel 5 集成

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

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

Messaging 外观添加到您的别名数组中。

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

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

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

要访问 Plivo/Messaging,您可以使用外观,或者 Messaging 实例绑定到 IOC 容器,然后通过其契约进行依赖注入。

Messaging::get('foo');

public function __construct(Midnite81\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 Midnite81\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);