blackford/twilio-bundle
Composer 安装命令:
composer require blackford/twilio-bundle
包简介
Symfony 5+ / PHP 8+ wrapper for the official Twilio SDK v6+
关键字:
README 文档
README
About
A quick and easy way to use the Twilio SDK (version 6) in a Symfony based application. Support for PHP 8+, Symfony >= 5.4. For full documentation about how to use the Twilio Client, see the official SDK provided by Twilio.
This bundle is a small wrapper around the official sdk. It just adds the basic auth and configs and avoid that you have to configure your service.yaml manual.
If you are already using the symfony/notifier component, habe a look at twilio-notifier.
Thank you for the awesome work of Fridolin Koch who created the first version of this bundle, with support for version 4 of the SDK.
Installation
composer req blackford/twilio-bundle
Configuration
Add these 2 parameters in .env.local and set it to your twilio credentials.
Please see Env-Variables for more details.
TWILIO_USER='!changeMe!' TWILIO_PASSWORD='!changeMe!'
Add a new file config/packages/twilio.yml and copy and adjust the following content:
blackford_twilio: # (Required) Username to authenticate with, typically your Account SID from www.twilio.com/user/account username: '%env(TWILIO_USER)%' # (Required) Password to authenticate with, typically your Auth Token from www.twilio.com/user/account password: '%env(TWILIO_PASSWORD)%' # (Optional) Account Sid to authenticate with, defaults to <username> (typically not required) # accountSid: # (Optional) Region to send requests to, defaults to no region selection (typically not required) # region:
Usage
Provided services:
| Service | Class |
|---|---|
twilio.client |
\Twilio\Rest\Client |
Inside a controller:
use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Twilio\Rest\Client as TwilioClient; class TestController extends Controller { public function __construct(private TwilioClient $twilioClient) {} public function smsAction() { $date = date('r'); $message = $this->twilioClient->messages->create( '+12125551234', // Text any number array( 'from' => '+14085551234', // From a Twilio number in your account 'body' => "Hi there, it's $date and Twilio is working properly." ) ); return new Response("Sent message [$message->sid] via Twilio."); } }
Inside a console command:
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Twilio\Rest\Client as TwilioClient; #[AsCommand(name: 'twilio:test:sms', description: 'Test the Twilio integration by sending a text message.')] class TwilioTestCommand extends ContainerAwareCommand { public function __construct(private TwilioClient $twilioClient) {} protected function execute(InputInterface $input, OutputInterface $output) { $date = date('r'); $message = $this->twilioClient->messages->create( '+12125551234', // Text any number array( 'from' => '+14085551234', // From a Twilio number in your account 'body' => "Hi there, it's $date and Twilio is working properly." ) ); $output->writeln("Sent message [$message->sid] via Twilio."); } }
Copyright / License
See LICENSE
blackford/twilio-bundle 适用场景与选型建议
blackford/twilio-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45.05k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twilio」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blackford/twilio-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blackford/twilio-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blackford/twilio-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Componente para integração com serviços de mensageria com APIs externas como Twilio, SendGrid, AWS SES, etc.
A Twilio SMS plugin for Yii2 based off my base package, Yii2 SMS, to make sending SMS messages as easy as emails!
Two-factor SMS authentication via Twilio Authy
Provides Twilio services in Laravel.
A simple Symfony bundle for Twilio API.
统计信息
- 总下载量: 45.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-27