如何使用 php laravel 在 twilio 中处理我的短信状态回调?
How to handle my sms statuscallback in twilio using php laravel?
我在twilio看到一个例子:https://www.twilio.com/docs/sms/tutorials/how-to-confirm-delivery-php
<?php
$sid = $_REQUEST['MessageSid'];
$status = $_REQUEST['MessageStatus'];
openlog("myMessageLog", LOG_PID | LOG_PERROR, LOG_USER);
syslog(LOG_INFO, "SID: $sid, Status: $status");
closelog();
我不知道上面的代码到底做了什么,但我想要的是将数据保存到我的本地数据库。
我的 post 方法中的代码(我的状态回调):
public function smsStatusCallback(Request $request){
$sms = SmsChannel::create([
'number' => $request['MessageSid'],
'body' => $request['MessageStatus'],
]);
}
我已经找到了解决办法。我在 twilio 调试器中看到了可能的解决方案:"Double check that your TwiML URL does not ..."。所以我试着把它做成 twiml
public function smsStatusCallback(Request $request){
$response = new Twiml();
$sms = SmsChannel::create([
'sid' => $request['MessageSid'],
'status' => $request['MessageStatus'],
]);
return response($response)
->header('Content-Type', 'text/xml');
}
我已经将我的路线添加到 api.php,因为 URL 应该可以被 twilio 访问。
Route::post('sms-status-callback','CommunicationController@smsStatusCallback');
我在twilio看到一个例子:https://www.twilio.com/docs/sms/tutorials/how-to-confirm-delivery-php
<?php
$sid = $_REQUEST['MessageSid'];
$status = $_REQUEST['MessageStatus'];
openlog("myMessageLog", LOG_PID | LOG_PERROR, LOG_USER);
syslog(LOG_INFO, "SID: $sid, Status: $status");
closelog();
我不知道上面的代码到底做了什么,但我想要的是将数据保存到我的本地数据库。
我的 post 方法中的代码(我的状态回调):
public function smsStatusCallback(Request $request){
$sms = SmsChannel::create([
'number' => $request['MessageSid'],
'body' => $request['MessageStatus'],
]);
}
我已经找到了解决办法。我在 twilio 调试器中看到了可能的解决方案:"Double check that your TwiML URL does not ..."。所以我试着把它做成 twiml
public function smsStatusCallback(Request $request){
$response = new Twiml();
$sms = SmsChannel::create([
'sid' => $request['MessageSid'],
'status' => $request['MessageStatus'],
]);
return response($response)
->header('Content-Type', 'text/xml');
}
我已经将我的路线添加到 api.php,因为 URL 应该可以被 twilio 访问。
Route::post('sms-status-callback','CommunicationController@smsStatusCallback');