Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Twilio REST API顺序拨号_Php_Rest_Twilio - Fatal编程技术网

Php Twilio REST API顺序拨号

Php Twilio REST API顺序拨号,php,rest,twilio,Php,Rest,Twilio,我真的不明白为什么我的代码不起作用,因为Twilio的调试器没有给我错误,所以我不知道该怎么办…我正在尝试使用Twilio在REST api中进行顺序拨号,所以它应该一直按顺序调用数字,直到有人接起。下面是我迄今为止编写的代码。我正在使用会话来跟踪呼叫 文件名:dial.php <?php session_start(); require 'Services/Twilio.php'; $version = "2010-04-01"; $arr = array('

我真的不明白为什么我的代码不起作用,因为Twilio的调试器没有给我错误,所以我不知道该怎么办…我正在尝试使用Twilio在REST api中进行顺序拨号,所以它应该一直按顺序调用数字,直到有人接起。下面是我迄今为止编写的代码。我正在使用会话来跟踪呼叫

文件名:dial.php

<?php
session_start();  



    require 'Services/Twilio.php';
    $version = "2010-04-01";

$arr = array('4167641123','6478604321','9058553456');



    $sid = '....';
    $token = '...';
    $from = '....';
    $to = '416.....';
    $callback = 'www.site.com/dial.php';

    $client = new Services_Twilio($sid, $token, $version);

    //if this is our very first call then CallStatus should be empty so it means we can use the emptiness of this variable
    //to trigger our very first call
    if (!(isset($_REQUEST['CallStatus'])))
    {
    try {
        $call = $client->account->calls->create(
            $from,
            $arr[0],
            'http://demo.twilio.com/welcome/voice/',
            array('Timeout' => 1,
                  'StatusCallback' => $callback)
            );
            var_dump($call);
        } catch (Exception $e) {
            var_dump($e);
        }
}
// if the CallStatus variable is not empty then the else statement will execute
else
{
//if this part of code runs for the first time, it means this is our 2nd call because the 1st person did not pick up
//this means the second number in the array will be called
//each time this statement runs it adds a 1 to the index of the array but if the last index number called was the final and 
//last number in the array, then this statement wont run and instead session at the bottom if statement will be initialized to 0
//so that if this script is ran again it will start off from the first number in the array
if (!($_SESSION['X']>=count($arr)-1) && isset($_REQUEST['CallStatus']) && ($_REQUEST['CallStatus']=='failed'|| $_REQUEST['CallStatus']=='no-answer' || $_REQUEST['CallStatus']=='busy'))
{

$_SESSION['X']=$_SESSION['X']+1;

    try {
        $call = $client->account->calls->create(
            $from,
            $arr[SESSION['X']],
            'http://demo.twilio.com/welcome/voice/',
            array('Timeout' => 1,
                  'StatusCallback' => $callback)
            );
            var_dump($call);
        } catch (Exception $e) {
            var_dump($e);
        }
}
//initializes the session to 0 because if we have reached to this else statement,
//then it means the if statement above did not run and we have already called the last person
//in the phone number array so we are at an end and we must close the program
//by leaving session at 0 for the next trial to run properly
else
{

$_SESSION['X']=0;

}

}

您的代码有语法错误等

例如
会话['X']=0没有执行您可能认为它正在执行的操作。如果这是一个会话变量,它应该写为
$\u session['X']=0

要发现这些问题,请启用最高级别的错误报告,然后将错误记录到文件中,然后查看该文件。它会给你一些提示


参见。

会话['X']=0那是什么语言?hakre我修复了那个会话错误,谢谢你指出我的思维太模糊了,只是完全忽略了那个!它打了第一个电话,但没有打第二个…错误报告的问题是,当我第一次运行代码时,它呼叫第一个号码,这很好,在那里没有报告错误,但是,当它为其他调用运行代码的2ndp部分时,会出现错误,但它不会显示错误,因为我将POST发送到dial.php,然后它的Twilio会发出StatusCallback POST请求,因此它们会看到错误,而不是我。我使用错误日志(print_r($请求,true));要打印$\u请求引起的错误,那么打印所有错误呢?
<?php 

// Set the numbers to call
$numbers = array("<number to call 1>", "<number to call 2>", "<number to call n>");
$number_index = isset($_REQUEST['number_index']) ? $_REQUEST['number_index'] : "0";
$DialCallStatus = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : "";

header("content-type: text/xml"); 

// Check the status of the call and 
// that there is a valid number to call

if($DialCallStatus!="completed" && $number_index<count($numbers)){ 
?>
    <Response>
    <Dial action="attempt_call.php?number_index=<?php echo $number_index+1 ?>">
        <Number url="screen_for_machine.php">
        <?php echo $numbers[$number_index] ?>
        </Number>
    </Dial>
    </Response>
<?php
} else {
?>
    <Response>
        <Hangup/>
    </Response>
<?php
}
?>