沃梦达 / 编程问答 / php问题 / 正文

如何接收短信并根据短信内容拨打电话提醒某人?

How do I take an SMS and make a call to alert someone based on what SMS says?(如何接收短信并根据短信内容拨打电话提醒某人?)

本文介绍了如何接收短信并根据短信内容拨打电话提醒某人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试接收收到的短信,并根据短信的内容拨打带有特定录音的电话.

So I am trying to take an incoming SMS and based on what the SMS says make a call with a specific recording.

例如:

我有一个带有调制解调器的门传感器,当门打开或门关闭时,它可以向我的 twilio # 发送文本.

I have a door sensor with a modem that can send a text to my twilio # when the door is open or when the door is closed.

如果 Twilio 收到开门"的文本,那么 twilio 会打电话给我的手机并播放开门"的录音

If Twilio receives "door open" text then twilio will call my cell phone and plays recording that says "door is open"

如果 Twilio 收到门已关闭"的文本,那么 twilio 将拨打我的手机并播放门已关闭"的录音

If Twilio receives "door closed" text then twilio will call my cell phone and plays recording that says "door is closed"

<?php
    require_once('/home/protranx/public_html/twilio-php-      latest/Services/Twilio.php');


    $sid = "SID";
    $token = "Token";
    $client = new Services_Twilio($sid, $token);
    $alert = $_REQUEST['body'];

    $TwilioNumber = "+twilio #";
    $to = "+my cell #";
    $url1 = "http://protran.x10.mx/Oak1_armed_door_open.php";
    $url2 = "http://protran.x10.mx/Oak1_disarmed_door_closed.php";

    $string1 = "door open";
    $string2 = "door closed"; 

    if ($alert == $string1){
        $call = $client->account->calls->create($TwilioNumber, $to, $url1);}


    elseif ($alert == $string2){
        $call = $client->account->calls->create($TwilioNumber, $to, $url2);}
echo $call->sid;


header('content-type: text/xml');
echo "<?xml version="1.0" encoding="UTF-8"?>
";
?>
<Response>
</Response>

我不断收到此错误:错误:12100 - 文档解析失败

I keep getting this error: Error: 12100 - Document parse failure

任何帮助将不胜感激.

谢谢

推荐答案

Twilio 布道者在这里.

Twilio evangelist here.

很难从您的代码中看出,因为它通常看起来是正确的.

Hard to tell from your code, as it generally looks right.

偶尔让我感到困惑的一件事是在 xml 开始之前或 xml 声明和根元素之间呈现空格,因此您可能会检查其中任何一个,因为这些可能难以捕捉.

One thing that occasionally trips me up is spaces being rendered before the start of the xml or between the xml declaration and the root element, so you might check for either of those that since those can be hard to catch.

例如,我不确定您是否需要 xml 声明末尾的换行符.

For example, I'm not sure you need the newline that you have at the end of your xml declaration.

希望有所帮助.

这篇关于如何接收短信并根据短信内容拨打电话提醒某人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何接收短信并根据短信内容拨打电话提醒某人?

基础教程推荐