繁体   English   中英

使用PHP和Twilio提取和存储SMS号码

[英]Pulling and storing SMS numbers with PHP and Twilio

因此,我刚开始使用Twilio(并且我的PHP有点生锈),但是当前代码会根据是否为您提供正确的数据来对文本进行数据响应,否则,它只是要求您重试一次。 这就是可行的方法。 但是,我希望做的是提取传入的SMS文本的数量并将它们暂时存储在Cookie中,这样我就可以根据其先前的响应获得不同的响应。

那有意义吗?

是! 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>

只需使用$ from = $ _REQUEST ['From'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM