intelogie / twiliosdk
Twilio API 的 PHP 封装
5.0.0-RC3
2016-03-28 21:30 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 4.5.*
- dev-master
- 5.2.x-dev
- 5.0.0-RC3
- 5.0.0-RC2
- 5.0.0-RC1
- 4.10.0
- 4.9.2
- 4.9.1
- 4.9.0
- 4.8.1
- 4.8.0
- 4.7.0
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.13.1
- 3.13.0
- 3.12.8
- 3.12.7
- 3.12.6
- 3.12.5
- 3.12.4
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.10.0
- 3.9.1
- 3.9.0
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- dev-next-gen
- dev-fix-paging
- dev-taskrouter-capability
- dev-twilio-capability-autoload
- dev-edge
- dev-add-actions-addresses
- dev-ip-messaging
- dev-identity-tokens
- dev-fix-grants
- dev-edge-release
- dev-token-generation-broken-link
- dev-addresses-create
- dev-ssl-cert-instructions
- dev-remove-pinned-certs
- dev-add-unmute-function
- dev-user-agent
- dev-std-class
- dev-transcription
- dev-sid-validation
This package is auto-updated.
Last update: 2024-09-21 19:45:52 UTC
README
安装
您可以通过 composer 安装 twilio-php,或者下载源代码。
通过 Composer
twilio-php 作为 twilio/sdk
包在 Packagist 上提供。
通过 ZIP 文件
点击此处下载源代码 (.zip),其中包括所有依赖项。
下载库后,将 twilio-php 文件夹移动到您的项目目录,然后包含库文件
require '/path/to/twilio-php/Services/Twilio.php';
然后您就可以使用了!
简介
使用 twilio-php 库,我们简化了与 Twilio REST API 的交互。无需手动创建 URL 或解析 XML/JSON。您现在可以直接与资源交互。按照 快速入门指南 立即开始使用。用户指南向您展示如何充分利用 twilio-php。
快速入门
发送短信
<?php // Install the library via PEAR or download the .zip file to your project folder. // This line loads the library require('/path/to/twilio-php/Services/Twilio.php'); $sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account $token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account $client = new Services_Twilio($sid, $token); $message = $client->account->messages->sendMessage( '9991231234', // From a valid Twilio number '8881231234', // Text this number "Hello monkey!" ); print $message->sid;
拨打电话
<?php // Install the library via PEAR or download the .zip file to your project folder. // This line loads the library require('/path/to/twilio-php/Services/Twilio.php'); $sid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account $token = "YYYYYY"; // Your Auth Token from www.twilio.com/user/account $client = new Services_Twilio($sid, $token); $call = $client->account->calls->create( '9991231234', // From a valid Twilio number '8881231234', // Call this number // Read TwiML at this URL when a call connects (hold music) 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient' );
生成 TwiML
为了控制电话,您的应用程序需要输出 TwiML。使用 Services_Twilio_Twiml
可以轻松创建此类响应。
<?php require('/path/to/twilio-php/Services/Twilio.php'); $response = new Services_Twilio_Twiml(); $response->say('Hello'); $response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5)); print $response;
这将输出如下所示的 XML
<?xml version="1.0" encoding="utf-8"?> <Response> <Say>Hello</Say> <Play loop="5">https://api.twilio.com/cowbell.mp3</Play> <Response>
完整文档
twilio-php 的文档托管在 Read the Docs 上。点击此处查看我们的完整文档。
先决条件
- PHP >= 5.2.3
- PHP JSON 扩展
获取帮助
如果您需要安装或使用库的帮助,请首先联系 Twilio 支持团队,邮箱为 help@twilio.com。Twilio 的支持团队精通所有 Twilio 辅助库,通常在 24 小时内回复。
如果您在库中发现了错误或希望添加新功能,请在此仓库中打开问题或拉取请求!