-1

我真的很沮丧,因为我无法弄清楚为什么我的 REST api 的Twilio callStatus不起作用:S ...有什么想法吗?

它在 stackoverflow.php 进行调用,但是当它到达 yournextnumber.php 时,它不会执行 if 语句,因为很可能 callStatus 中没有值,知道为什么没有发送状态吗?

堆栈溢出.php

<?php
// Include the Twilio PHP library
require 'Services/Twilio.php';

// Twilio REST API version
$version = "2010-04-01";

// Set our Account SID and AuthToken
$sid = '....';
$token = '....';


// A phone number you have previously validated with Twilio
$phonenumber = '....';

// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
  // Initiate a new outbound call
  $call = $client->account->calls->create(
    $phonenumber, // The number of the phone initiating the call
    '....', // The number of the phone receiving call
    'http://demo.twilio.com/welcome/voice/',
    array('Timeout'=>5,
          'IfMachine'=>'hangup',
          'StatusCallback'=>'http://example.com/twilio-twilio-php-28c214f/yourNextNumberHandler.php'));

  echo 'Started call: ' . $call->sid;
  echo 'The status of the call is '.$call->status;
} catch (Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
?>

yourNextNumber.php

  <?php
// Include the Twilio PHP library
    require 'Services/Twilio.php';

    // Twilio REST API version
    $version = "2010-04-01";
    print_r()//error_log() $_REQUEST
    // Set our Account SID and AuthToken
    $sid = '....';
    $token = '....';


// A phone number you have previously validated with Twilio
    $phonenumber = '....';

// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);


if ($_REQUEST['CallStatus']=='completed')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'..', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}

}   



if ($_REQUEST['CallStatus']=='no-answer')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'...', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}


if ($_REQUEST['CallStatus']=='ringing')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'....', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}


if ($_REQUEST['CallStatus']=='busy')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'...', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}

if ($_REQUEST['CallStatus']=='queued')
{

try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'....', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/',
array('Timeout'=>5)
);

}
catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}

    ?>
4

2 回答 2

2

你检查过你的 PHP 错误日志吗?您需要catch为每个try块提供一个。

于 2011-08-13T00:14:12.783 回答
1

不使用 if 语句进行 CallStatus 处理,而是将其转换为 switch 语句。这样,您就可以设置不管状态如何都会执行的默认案例。然后,当您发现意外的 CallStatus 时,您可以轻松记录(或通知某人)。

于 2011-08-16T03:11:27.487 回答