Php 当用户使用Twilio通过短信停止回复时,如何使用用户号码进行回调?
我想知道如何获得用户的号码或一些数据来更新数据库,当用户通过短信停止回复时,使用Twilio的回调从我的服务器中选择出来 我正在使用PHP 如何解决这个问题?我将$\u POST['Body']与一些过滤函数进行了比较,下面是我的完整代码:Php 当用户使用Twilio通过短信停止回复时,如何使用用户号码进行回调?,php,twilio,twilio-api,twilio-php,Php,Twilio,Twilio Api,Twilio Php,我想知道如何获得用户的号码或一些数据来更新数据库,当用户通过短信停止回复时,使用Twilio的回调从我的服务器中选择出来 我正在使用PHP 如何解决这个问题?我将$\u POST['Body']与一些过滤函数进行了比较,下面是我的完整代码: // You need to include Twilio library path here... for example require_once '/path/to/twilio-lib/autoload.php'; use Twilio\Twiml;
// You need to include Twilio library path here... for example require_once '/path/to/twilio-lib/autoload.php';
use Twilio\Twiml;
global $wpdb;
$response = new Twiml;
if (!empty($_POST))
{
$number = $_POST['From'];
$body = $_POST['Body'];
$default = "Hi " .$number. ", I'm a bot, please do not reply until you will get an update in some day. Have a nice day!";
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body);
$result = trim($result);
$result = strtolower($result);
//words to match and $result must be lowercase to define.
if ($result == 'stop' || $result == 'stopall' || $result == 'cancel' || || $result == 'end') || $result == 'quit' || $result == 'unsubscribe'{
//Your function to update database with $number
}
else if ($result == 'start' || $result == 'yes' || $result == 'unstop'){
$response->message('Thanks for re-subscribing');
//Your function to update database, again with $number
}
else {
$response->message($default);
}
print $response;
}
到目前为止,你尝试了什么?@Demon我遵循了这一点,我的服务器回复了我的手机,而且我确实停止了取消注册并开始重置,无论如何,我不知道如何在执行回调和更新数据库之前检测停止。@Ivan这基本上是如果处理程序中的$_POST['Body']=='stop'{//do some}。比这稍微复杂一点-您可能希望使用trim处理额外的空格,使其不区分大小写,等等,但这是一般的想法…@ceejayoz我也在想,但如何获取电话号码,我需要用户提供的任何类型的数据,以便在执行选择退出之前可以在数据库中查找匹配。如果您停止使用$number文本,完全停止发送给它。你应该有一个数据库的选择了数字,你检查之前发送任何东西。Twilio有效载荷的全部内容为。