1

我正在使用 Twilio 开发一个 IVR 应用程序并使用 [record] 标签对某人的姓名进行简短记录。

所以 page1.php 看起来像这样:

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
     <Say>Please state your name after the tone</Say>
     <Record maxLength="20" finishOnKey="#" playBeep="true" action="page2.php" />
</Response>

这很好,并且 RecordingURL 值按原样传递到 page2.php 中。但是,在 page2.php 上,我要求用户输入他们的参考号,并且需要将 RecordingURL 值传递给 page3.php。

Page2.php

<?php   
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$rec_url=$_REQUEST['RecordingUrl'];
?>
<Response>
<Gather timeout="7" finishOnKey="#" numDigits="3" action="page3.php?rec_url=<?php echo   $_REQUEST['RecordingUrl']; ?>" method="POST">
<Say>Please now enter your reference number</Say>
</Gather>
</Response>

Page3.php

<?php 
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$ref_no=$_REQUEST['Digits'];
$cli=$_REQUEST['From'];  
$rec_url=$_GET['rec_url'];
$nodialled=$_REQUEST['To'];
?>
<Response>
<Say>Thank you. Goodbye.</Say>
</Response>

<?php
$ref_no=$_POST['Digits'];
$cli=$_POST['From'];  
$recording_url=$_POST['rec_url'];
$nodialled=$_POST['To'];
$html="<br />";

file_put_contents("test.html", "CLI: $cli $html Number Dialled: $nodialled $html   Reference: $ref_no $html Recording URL: $recording_url");

?>

有任何想法吗?

4

2 回答 2

1

SimonR91 提到他通过在操作之前构建查询字符串来实现这一点。

这也是我能找到的在 Twilio 中传递变量的唯一方法。

但是,需要澄清的一点是您不能使用:

if (isset $_GET["variable"])
{
  $variable = $_GET["variable"];
}

这会导致 Twilio 返回忙信号。

相反,您必须 $_GET 相信它存在的变量。此外,您不能在调用开始时直接从 Twilio 传递变量。你必须有一个脚本来启动调用,然后是第二个脚本,它可以继续将变量传递给它自己。

于 2013-07-25T17:10:01.827 回答
0

尝试:

<Gather timeout="7" finishOnKey="#" numDigits="3" action="page3.php?rec_url=<?php echo $_REQUEST['RecordingUrl']; ?>"

将其作为 GET 发送,因为在 page3.php 上您使用 GET 接受它$rec_url=$_GET['rec_url'];

或尝试通过 post 在 page3 上获取它:

$rec_url=$_POST['rec_url'];

编辑
您可以尝试在所有页面上启动会话:

<?php start_session(); ?>

然后将其设置在 page2.php 上,例如:

 $_SESSION['RecordingUrl']=$rec_url;

那么您可以在 page3.php 上将其作为:

$rec_url=$_SESSION['RecordingUrl'];
于 2013-06-28T08:22:28.103 回答