所以我是使用Twilio的新手(我的PHP有点生疏)但是目前代码会根据您是否提供正确的数据来响应文本,否则,它只是要求您再次尝试。这就是有效的。但是,我希望这样做的目的是提取传入的SMS文本的数量,并暂时将它们存储在cookie中,这样我就能根据之前的响应得到不同的响应。
这有意义吗?
答案 0 :(得分:1)
是的! Twilio让这很简单。您设置的任何Cookie都将保存在两个号码(您的来电号码和发件人)之间。所有代码和解释都在这里:http://www.twilio.com/docs/quickstart/sms/tracking-conversations
以下是该页面的快速摘要,可以执行您想要的操作:
<?php
// start the session
session_start();
// get the session varible if it exists
$counter = $_SESSION['counter'];
// if it doesnt, set the default
if(!strlen($counter)) {
$counter = 0;
}
// increment it
$counter++;
// save it
$_SESSION['counter'] = $counter;
// make an associative array of senders we know, indexed by phone number
$people = array(
"+14158675309"=>"Curious George",
"+14158675310"=>"Boots",
"+14158675311"=>"Virgil",
);
// if the sender is known, then greet them by name
// otherwise, consider them just another monkey
if(!$name = $people[$_REQUEST['From']])
$name = "Monkey";
// output the counter response
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms><?php echo $name ?> has messaged <?php echo $_REQUEST['To']." ".$counter ?> times</Sms>
</Response>
答案 1 :(得分:0)
只需使用$ from = $ _REQUEST ['From'];