cloudonix/cxml-php

Cloudonix CXML 语言的 PHP 封装库

dev-master 2024-08-28 20:46 UTC

This package is auto-updated.

Last update: 2024-09-28 21:05:33 UTC


README

Contributors Packagist

文档

Cloudonix CXML 标记语言的文档可以在这里找到。

PHP 库文档可以在这里找到。

支持的 PHP 版本

此库支持以下 PHP 版本

  • PHP 8.0
  • PHP 8.1
  • PHP 8.2
  • PHP 8.3

安装

您可以通过 composer 或下载源代码来安装 cxml-php

composer require cloudonix/cxml-php

测试您的安装

以下是一个示例 PHP 脚本,它将使用库生成一个 CXML 语音应用程序文档

<?php

require(__DIR__ . "/vendor/autoload.php");

use Cloudonix\CXML\Response;

$responder = new Response();
$responder->dial("12127773456");
$responder->redirect("https://example.com/script.php");

$responder->gather([
    (new Response())->play("https://example.com/playfile.mp3")->attributes(["loop" => 3]),
    (new Response())->pause()->attributes(["length" => 5]),
])->attributes(["action" => "https://example.com/script.php"]);

$responder->hangup();

echo $responder;

将上面的脚本复制并粘贴到一个新文件中,然后从命令行执行它,以下应该是结果

$ php cxmlResponder.php 
<Response>
  <DIAL>12127773456</DIAL>
  <REDIRECT>https://example.com/script.php</REDIRECT>
  <GATHER action="https://example.com/script.php">
    <PLAY loop="3">https://example.com/playfile.mp3</PLAY>
    <PAUSE length="5" />
  </GATHER>
  <HANGUP />
</Response>

用法

使用 <PLAY><HANGUP> 创建 CXML 文档响应

<?php

require(__DIR__ . "/vendor/autoload.php");

use Cloudonix\CXML\Response;

$responder = new Response();
$responder
    ->play("https://example.com/playfile.mp3")
    ->attributes([
        "loop" => 3,
        "statusCallback" => "https://example.com/statusCallback"
    ]);
$responder->hangup();

echo $responder;

预期结果

<Response>
  <PLAY loop="3" statusCallback="https://example.com/statusCallback">https://example.com/playfile.mp3</PLAY>
  <HANGUP />
</Response>

创建一个包含 <GATHER><PLAY><PAUSE><HANGUP> 的 CXML 文档响应

<?php

require(__DIR__ . "/vendor/autoload.php");

use Cloudonix\CXML\Response;

$responder = new Response();
$responder->gather([
    (new Response())->play("https://example.com/playfile.mp3")->attributes(["loop" => 3]),
    (new Response())->pause()->attributes(["length" => 5]),
])->attributes(["action" => "https://example.com/script.php"]);
$responder->hangup();

echo $responder;

预期结果

<Response>
  <GATHER action="https://example.com/script.php">
    <PLAY loop="3">https://example.com/playfile.mp3</PLAY>
    <PAUSE length="5" />
  </GATHER>
  <HANGUP />
</Response>

获取帮助

如果您需要安装或使用库的帮助,请首先检查Cloudonix 开发者网站

如果您在库中发现了错误或者想添加新功能,请在此仓库中打开问题或拉取请求!