ini_set('max_execution_time', 3000);
require 'Services/Twilio.php';
$version = "2010-04-01";
$sid = 'xxxxxx';
$token = 'xxxxxx';
$phonenumber = 'xxxxxxxxxx';
$client = new Services_Twilio($sid, $token, $version);
try {
$call = $client->account->calls->create($phonenumber, "3104200693", "http://demo.twilio.com/docs/voice.xml", array(
"Method" => "GET",
"StatusCallback" => "http://localhost/twilio/call-response.php",
"StatusCallbackMethod" => "GET",
"StatusCallbackEvent" => array("initiated", "ringing", "answerswered", "completed"),
"IfMachine" => "Continue",
));
//header("Location: http://localhost/twilio/call-response.php");
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
这是我拨打号码的 twilio 代码,我用这个成功拨打,但我想将响应存储在数据库中,例如呼叫是否完成,如果接听,那么谁接听呼叫人或机器。
请帮忙。
Twilio 服务器将向 URL 发送 HTTP 请求,StatusCallback
。很明显,希望Twilio无法联系到您的localhost
。1)您的计算机可能无法从网络外部物理访问,2)localhost
对每个人来说都是不同的。
您需要提供一个可从互联网公开访问的 URL。这意味着您要么需要在服务器中运行代码,要么在开发过程中使用 http://ngrok.com 等服务建立到本地计算机的隧道。
我认为"StatusCallback" => "http://localhost/twilio/call-response.php"
不会让你得到呼叫响应。您应该提供一个服务器 URL。
例如
"StatusCallback" => "http://example.com/twilio/call-response.php"
在呼叫响应.php中,
<?php
file_put_contents(__DIR__."/status_log.txt", json_encode($_REQUEST));
// twilio call status and other sata will be written to this file. Please check this file after call.
// I am giving because i dont know correct twilio returning params
?>
更多信息在这里