tiniyo / tiniyo-php
此包最新版本(v1.1.3)没有提供许可证信息。
tiniyo api 的 PHP SDK
v1.1.3
2021-01-18 09:39 UTC
Requires
- php: >=7.1.0
- twilio/sdk: ^6.16
README
tiniyo-php 为 tiniyo api 提供SDK。
支持的 PHP 版本
此库支持以下 PHP 实现
- PHP 7.2
- PHP 7.3
- PHP 7.4
- PHP 8.0.1
安装
您可以通过 composer 安装 tiniyo-php 或下载源代码。
通过 Composer
tiniyo-php 作为 tiniyo/tiniyo-php
包在 Packagist 上可用
composer require tiniyo/tiniyo-php
快速入门
发送短信
// Send an SMS using tiniyo's REST API and PHP <?php $sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com $token = "YYYYYY"; // Your Auth Token from https://tiniyo.com $client = new Tiniyo\Rest\Client($sid, $token); $message = $client->messages->create( '8881231234', // Text this number [ 'from' => '9991231234', // From a valid Tiniyo number or approved senderid 'body' => 'Hello from Tiniyo!' ] ); print $message->sid;
拨打电话
<?php $sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com $token = "YYYYYY"; // Your Auth Token from https://tiniyo.com $client = new Tiniyo\Rest\Client($sid, $token); // Read tinixml at this URL when a call connects (hold music) $call = $client->calls->create( '8881231234', // Call this number '9991231234', // From a valid Tiniyo number [ 'url' => 'https://raw.githubusercontent.com/tiniyo/public/master/answer_speak.xml' ] );
启用调试日志
您可以将日志级别设置为调试,以在默认的 HTTP 客户端中启用调试日志
$sid = "ACXXXXXX"; // Your Account SID from https://tiniyo.com $token = "YYYYYY"; // Your Auth Token from https://tiniyo.com $client = new Tiniyo\Rest\Client($sid, $token); $client->setLogLevel('debug');
生成 Tinixml
为了控制电话通话,您的应用程序需要输出 Tinixml。
使用 Tiniyo\Tinixml\(Voice|Messaging|Fax)Response
可以轻松串联响应。
<?php $response = new Tiniyo\Tinixml\VoiceResponse(); $response->say('Hello'); $response->play('https://api.tiniyo.com/cowbell.mp3', ['loop' => 5]); print $response;
这将输出类似以下的 XML
<?xml version="1.0" encoding="utf-8"?> <Response> <Say>Hello</Say> <Play loop="5">https://api.tiniyo.com/cowbell.mp3</Play> </Response>