如何将回调URL添加到Twilio SMS发送代码



我正在使用官方的php twilio库代码发送和接收呼叫。我可以使用下面的示例代码发送SMS:

<?php
require('twilio/Twilio.php');
$sid = "AC************";
$token = "2************";
$client = new Services_Twilio($sid, $token);
$message = $client->account->sms_messages->create(
  '+1905xxxxxxx', // From a valid Twilio number
  '+278xxxxxxxx', // Text this number
  "Hello, test SMS message number 001!"
);
?>

现在,我将回调URL添加到上述代码中。它可以做到,但是我不知道如何添加$ params的数组。

function create($from, $to, $body, array $params = array()) {
    return parent::_create(array(
        'From' => $from,
        'To' => $to,
        'Body' => $body
    ) + $params);
}

感谢您的帮助

尝试以下

function create($from, $to, $body, array $params = array()) {
    return parent::_create(array(
        'From' => $from,
        'To' => $to,
        'Body' => $body
    ) + array('StatusCallback'=>'http://yourdomain.com/yoururl.php'));
}

$message = $client->account->sms_messages->create(
  '+1905xxxxxxx', // From a valid Twilio number
  '+278xxxxxxxx', // Text this number
  "Hello, test SMS message number 001!",
   array('StatusCallback'=>'http://yourdomain.com/yoururl.php')
);

您可以在此处发送SMS时了解有关如何使用StatusCallback的更多信息。

最新更新