How to add the callback URL to Twilio SMS sending code?

风格不统一 提交于 2019-12-11 03:49:15

问题


I'm using the official PHP Twilio library code for sending and receiving call. I can send an SMS using the example code below:

<?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!"
);
?>

Now I wan to add the callback URL to the above code. It can do it, but I don't know how to add the array for the $params.

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

Thanks for the help


回答1:


Try as below

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'));
}

OR

$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')
);

You can learn more about how to use StatusCallback when sending sms here.



来源:https://stackoverflow.com/questions/13212047/how-to-add-the-callback-url-to-twilio-sms-sending-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!