我是 twilio api 的新手。在正在开发的 Web 应用程序中,我必须检查呼叫是否完成,并且我正在将 wav 文件发送到 twiml。如果完成,我必须扣除用户的信用..我正在使用以下代码...
callMeAction
$AccountSid = "**********************";
$AuthToken = "***************";
/* Your Twilio Number or an Outgoing Caller ID you have previously validated
with Twilio */
$from = '**************';
/* Number you wish to call */
$to = $_POST['contactno'];
/* Directory location for callback.php file (for use in REST URL) */
$url = 'http://'.$_SERVER['HTTP_HOST'].'/public/';
/* Instantiate a new Twilio Rest Client */
$client = new Services_Twilio($AccountSid, $AuthToken);
/* make Twilio REST request to initiate outgoing call */
$call = $client->account->calls->create($from, $to, $url . 'callback.php?number=' . $_POST['contactno'] . '&wav=' . $_POST['wav']);
/* redirect back to the main page with CallSid */
$msg = urlencode("Connecting... " . $call->sid);
//header("Location: index.php?msg=$msg");
$this->view->msg = $msg;
if($call->status == 'COMPLETED'){
/*
* Deduct credit if call completed
*/
$this->view->msg = $msg;
}
回调.php
<?php
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<?php if($_REQUEST['wav']){ ?>
<Response>
<Say>A customer at the number <?php echo $_REQUEST['number']?> is calling</Say>
<Dial><?php echo $_REQUEST['number']?></Dial>
<Play><?php echo $_REQUEST['wav'] ;?></Play>
</Response>
<?php } ?>
请帮助我...提前谢谢。:)