Twilio帮助让callerId在php中显示To

时间:2015-07-13 14:38:18

标签: php xml twilio twilio-php

我正在尝试让调用者在xml中显示调用者ID,如您所见。我怎样才能做到这一点?我究竟做错了什么?我似乎无法把一切都搞定。我需要一些帮助,我不擅长编码,我已经在互联网上查询如何获得大部分内容,但我无法让我的代码工作。提前致谢!

<?xml version='1.0' encoding='UTF-8'?> <TwilioResponse><Call><To>+12017447179</To><ToFormatted>(201) 744-7179</ToFormatted><From>+16463621515</From><FromFormatted>(646) 362-1515</FromFormatted><PhoneNumberSid/><Status>queued</Status><StartTime/><EndTime/><Duration/><Price/><PriceUnit>USD</PriceUnit><Direction>outbound-api</Direction><AnsweredBy/><ApiVersion>2010-04-01</ApiVersion><Annotation/><ForwardedFrom/><GroupSid/><CallerName/></Call></TwilioResponse>


http://gordonbusiness.com/vb_menu.xml


<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="="/forward_call.php" numDigits="1">
<Play loop="2">https://gordonbusiness.com/studentloan.mp3</Play>
</Gather>
<Say>Sorry, I didn't get your response.</Say>
<Redirect>vb_menu.xml</Redirect>
</Response>

http://gordonbusiness.com/forward_call.php -

Response sent to 2nd URL:
1   $user_pushed = (int) $_REQUEST['Digits'];


<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Response>';
# @start snippet$
user_pushed = (int) $_REQUEST['Digits'];
# @end snippet
$string_data = "<TwilioResponse>";
$xml = simplexml_load_string($string_data);
$phonenumber == (string) $xml->To;
if ($user_pushed == 1)
{
echo '<Dial callerId=$phonenumber>
<Number>+18552426127</Number>
</Dial>';
}
else if ($user_pushed == 9)
{
echo '<Hangup />';
}

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

我认为你有大部分权利,缺少的是将拨打的号码作为来电显示。

您似乎正在使用您创建的某个匿名XML结构构建To编号。您可以从请求参数中获取To编号。就像你得到Digits参数一样。

所以,而不是

$string_data = "<TwilioResponse>";
$xml = simplexml_load_string($string_data);
$phonenumber == (string) $xml->To;

您可以将$phonenumber设置为:

$phonenumber = $_REQUEST["To"];

让我知道这是否有帮助。