0

我想在 1 号和 2 号之间进行实时对话。我的代码如下 -

<?php
require 'twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
$sid = "******************";
$token = "***************"; 

$client = new Client($sid, $token);


  try {
        // Initiate a new outbound call
        $call = $client->account->calls->create(
            // Step 4: Change the 'To' number below to whatever number you'd like 
            // to call.
            "Number 2",

            // Step 5: Change the 'From' number below to be a valid Twilio number 
            // that you've purchased or verified with Twilio.
            "Number 1",

            // Step 6: Set the URL Twilio will request when the call is answered.
            array("url" => "twiml_url")
        );
        echo "Started call: " . $call->sid;
    } catch (Exception $e) {
        echo "Error: " . $e->getMessage();

?>

下面给出了我的 twiML -

    <?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Dial callerId="Number 1">
      <Number>Number 2</Number>
  </Dial>
</Response>

当我在浏览器中点击此 REST api 时,我在手机中接到电话,但在试用帐户消息后电话断开连接。请帮我。

4

1 回答 1

0

您在此处指定的网址

// Step 6: Set the URL Twilio will request when the call is answered.

需要返回一些 TwiML 来告诉 Twilio 下一步该做什么。您的呼叫正在断开,因为 Twilio 已用完要执行的 TwiML。

将您的请求 URL 设置为返回 TwiML,它会呼叫另一个号码,然后运行您的第一个脚本将呼叫您的电话,一旦您拿起它将呼叫他们的电话并连接两个呼叫。

于 2017-10-06T20:53:10.150 回答