如何将回调 URL 添加到 Twilio SMS 发送代码? [英] How to add the callback URL to Twilio SMS sending code?
本文介绍了如何将回调 URL 添加到 Twilio SMS 发送代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用官方 PHP Twilio 库代码来发送和接收呼叫.我可以使用以下示例代码发送短信:
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!"
);
?>
现在我想将回调 URL 添加到上述代码中.它可以做到,但我不知道如何为 $params 添加数组.
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);
}
感谢您的帮助
推荐答案
尝试如下
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')
);
您可以详细了解如何在发送短信时使用 StatusCallback
此处.
You can learn more about how to use StatusCallback
when sending sms here.
这篇关于如何将回调 URL 添加到 Twilio SMS 发送代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文