定制 blackford/twilio-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Configure your Twilio-Account

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 blackford/twilio-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 45.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 44
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-27