fortifycode/full-sms

集成Nexmo、Twilio和WhatsApp的Laravel SMS服务

dev-master 2015-07-07 00:09 UTC

This package is auto-updated.

Last update: 2024-09-08 12:32:07 UTC


README

集成Nexmo、Twilio和WhatsApp消息的Laravel SMS服务

描述

本项目允许您在Laravel 5项目中集中且简单地使用SMS消息服务。

状态

此第一个版本将允许您使用Nexmo和Twilio发送和接收SMS。
未来的版本将使用API的其他功能,并将包括WhatsApp。

安装

composer require fortifycode/full-sms

设置

修改文件 config/app 以将提供者添加到列表中

'providers' => [
// ...
    'FortifyCode\FullSms\FullSmsServiceProvider',
// ...
],

然后发布配置文件到您的本地配置目录

php artisan vendor:publish

现在您应该在配置文件中输入您的API账户信息,并选择默认的提供者

return array(
    'default_provider' => 'twilio',
    'provider_aliases' => [
        'twilio' => 'FortifyCode\FullSms\Providers\TwilioSmsProvider',
        'nexmo' => 'FortifyCode\FullSms\Providers\NexmoSmsProvider',
    ],
    'twilio' => [
        'sid' => '',
        'token' => '',
        'default_number' => '',
    ],
    'nexmo' => [
        'api_key' => '',
        'api_secret' => '',
        'default_number' => '',
    ],
);

使用方法

现在您可以使用工厂来检索相应的提供者

use FortifyCode\FullSms\MessageSenderFactory;

class MyClass {

    public function do_something() {
        // This one gets the default sender according to the configuration
        $default_sender =  MessageSenderFactory::make();
        
        // Using a specific sender using the alias from the configuration
        $nexmo_sender =  MessageSenderFactory::make('nexmo');
    }

}

使用这种方法,您可以基于用户的配置或其他参数选择要使用的提供者。
您还可以根据需要更改别名或添加更多别名。

作者

Nestor Mata Cuthbert

许可证

MIT