Twilio转发短信到不同数量的PHP

时间:2015-05-10 16:43:35

标签: php sms twilio outbound inbound

这是我的问题。 我将短信发送到我的twilio应用程序,根据其中的文字,我想要一个不同号码的短信回复。 好吧,我从一个例子开始,我的应用程序接收短信,回复相同的号码要求输入一些单词但是当它得到答复时,没有短信到达另一个号码(两个号码都在代码中的twilio中注册下面我编辑了最后的数字)

这是代码

<?php
include 'Services/Twilio.php';
include 'config.php';
    // make an associative array of callers we know, indexed by phone number
    $people = array(
        "+3932034091XX"=>"3934781415XX",
        "+3934781415XX"=>"+3932034091XX",
        "+14158675311"=>"Virgil",
        "+14158675312"=>"Marcel"
    );


$name=$people[$_REQUEST['From']];

function index($name){
    $response = new Services_Twilio_Twiml();

    $response->sms("Reply $name with one of the following keywords:
batteria, dog, pigeon, owl.");
    echo $response;
}

function batteria($name){
$dest=$name;

$client = new Services_Twilio($TWILIO_ACCOUNT_SID, $TWILIO_AUTH_TOKEN);
$sms = $client->account->messages->create(

        // Step 6: Change the 'From' number below to be a valid Twilio number
        // that you've purchased, or the (deprecated) Sandbox number
            $TWILIO_NUMBER,


            // the number we are sending to - Any phone number
            $dest,

            // the sms body
            "Hey  Cambia la batteria!"
        );



}

function dog(){
    $response = new Services_Twilio_Twiml();
    $response->sms("Dog. A domesticated carnivorous mammal that
typically has a long snout, an acute sense of smell, and a barking,
howling, or whining voice.");
    echo $response;
}

function pigeon(){
    $response = new Services_Twilio_Twiml();
    $response->sms("Pigeon. A stout seed- or fruit-eating bird with
a small head, short legs, and a cooing voice, typically having gray and
white plumage.");
    echo $response;
}

function owl(){
    $response = new Services_Twilio_Twiml();
    $response->sms("Owl. A nocturnal bird of prey with large
forward-facing eyes surrounded by facial disks, a hooked beak,
and typically a loud call.");
    echo $response;
}

/* Read the contents of the 'Body' field of the Request. */
$body = $_REQUEST['Body'];

/* Remove formatting from $body until it is just lowercase
characters without punctuation or spaces. */
$result = preg_replace("/[^A-Za-z0-9]/u", " ", $body);
$result = trim($result);
$result = strtolower($result);

/* Router: Match the ‘Body’ field with index of keywords */
switch ($result) {
    case 'batteria':
        batteria($name);
        break;
    case 'dog':
        dog();
        break;
    case 'pigeon':
        pigeon();
        break;
    case 'owl':
        owl();
        break;

/* Optional: Add new routing logic above this line. */
    default:
        index($name);
}
?> 

感谢所有人

0 个答案:

没有答案