2012-01-03 19 views
1

如何通过向tropo托管的脚本发送xml来使用tropo进行电话呼叫? 这个PHP脚本应该使用curl将xml发布到另一个php脚本(托管@ tropo)。然后,tropo托管的脚本应该使用xml来拨打电话。在下面的例子中,TROPO调试器接收到正确的信息,因为这样的消息在调试器中显示:通过托管php tropo脚本接收xml文件

customerName:Kent is added into the context of app instance : ApplicationInstance[http://hosting.tropo.com/107029/www/ExternalPhoneHelper.php , sas_2-14-sm25ogjh4vlab5tropo] 

下面是XML数据发送到TROPO卷曲PHP脚本:

$token = "mytoken";//removed actual token 
$url = PhoneHelper::$TROPO_URL; 
$xml = " 
    <session> 
     <token>" . $token . "</token> 
     <var name=\"action\" value=\"create\"/> 
     <var name=\"customerName\" value=\"Kent\" /> 
     <var name=\"numberToDial\" value=\"##########\" /> 
     <var name=\"msg\" value=\"XML Test\" /> 
    </session>"; 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
echo curl_error($ch); 
echo $output; 
curl_close($ch); 

接收程序是空的:

<?php 

?> 

如果调用(),说(应使用)的方法,我将如何引用发布XML获得numberToDial和味精?

这里是调试日志:

|-----------------------------------------------------------------------| 
    |00000|00-1|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 | 
    |  | |   |to accountID=107029 host=tropo203.orl.voxeo.net | 
    |  | |   |sessionGUID=-1 sessionNumber=-1 callID=-1  | 
    |-----------------------------------------------------------------------| 
    |00001|00-1|02:18:47 AM|Attempting to determine application type via | 
    |  | |   |tropo-engine URL parameter in myURL   | 
    |-----------------------------------------------------------------------| 
    |00002|00-1|02:18:47 AM|Attempting to determine application type by  | 
    |  | |   |requesting HEAD from       | 
    |  | |   |myURL to get Content-Type header    | 
    |-----------------------------------------------------------------------| 
    |00003|00-1|02:18:47 AM|Opened URLConnection       | 
    |-----------------------------------------------------------------------| 
    |00004|00-1|02:18:47 AM|Connecting for HEAD        | 
    |-----------------------------------------------------------------------| 
    |00005|00-1|02:18:47 AM|Got HEAD response        | 
    |-----------------------------------------------------------------------| 
    |00006|00-1|02:18:47 AM|No Content-Type header provided by HEAD.  | 
    |-----------------------------------------------------------------------| 
    |00007|00-1|02:18:47 AM|Attempting to determine application type based | 
    |  | |   |on file extension for myURL      | 
    |-----------------------------------------------------------------------| 
    |00008|00-1|02:18:47 AM|Determined type=php from filename suffix  | 
    |-----------------------------------------------------------------------| 
    |00009|00-1|02:18:47 AM|Trying to create application for URL=myURL  | 
    |-----------------------------------------------------------------------| 
    |00010|00-1|02:18:47 AM|Tropo app dir is /tropo_app_home    | 
    |-----------------------------------------------------------------------| 
    |00011|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 | 
    |  | |   |to accountID=107029 host=tropo203.orl.voxeo.net | 
    |  | |   |sessionGUID=0 sessionNumber=0 callID=0   | 
    |-----------------------------------------------------------------------| 
    |00012|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been  | 
    |  | |   |created.          | 
    |-----------------------------------------------------------------------| 
    |00013|0000|02:18:47 AM|Found hosted Application[myURL ver(1.0.56092) | 
    |  | |   |[token=myToken]         | 
    |-----------------------------------------------------------------------| 
    |00014|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 | 
    |  | |   |to accountID=107029 host=tropo203.orl.voxeo.net | 
    |  | |   |sessionGUID=0 sessionNumber=0 callID=0   | 
    |-----------------------------------------------------------------------| 
    |00015|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been found.| 
    |-----------------------------------------------------------------------| 
    |00016|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 | 
    |  | |   |to accountID=107029 host=tropo203.orl.voxeo.net | 
    |  | |   |sessionGUID=0         | 
    |  | |   |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |  | |   |callID=0          | 
    |-----------------------------------------------------------------------| 
    |00017|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 acquired engine | 
    |  | |   |QuercusScriptEngine[] of type php,    | 
    |  | |   |activeEngines = 5        | 
    |-----------------------------------------------------------------------| 
    |00018|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 got engine to  | 
    |  | |   |compile script         | 
    |-----------------------------------------------------------------------| 
    |00019|0000|02:18:47 AM|?><?php // line 1121       | 
    |-----------------------------------------------------------------------| 
    |00020|0000|02:18:47 AM|if ($currentCall != null) // line 1122  | 
    |-----------------------------------------------------------------------| 
    |00021|0000|02:18:47 AM|{ // line 1123        | 
    |-----------------------------------------------------------------------| 
    |00022|0000|02:18:47 AM| say("I'm sorry, but I can not find or  | 
    |  | |   |compile the Tropo script for this phone number."| 
    |  | |   |); // line 1124        | 
    |-----------------------------------------------------------------------| 
    |00023|0000|02:18:47 AM| hangup(); // line 1125      | 
    |-----------------------------------------------------------------------| 
    |00024|0000|02:18:47 AM|} // line 1126        | 
    |-----------------------------------------------------------------------| 
    |00025|0000|02:18:47 AM|?> // line 1127        | 
    |-----------------------------------------------------------------------| 
    |00026|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returning engine | 
    |  | |   |after compiling script       | 
    |-----------------------------------------------------------------------| 
    |00027|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returned engine | 
    |  | |   |QuercusScriptEngine[] of type php,    | 
    |  | |   |activeEngines = 4        | 
    |-----------------------------------------------------------------------| 
    |00028|0000|02:18:47 AM|In SimpleApplication.execute() for token launch,| 
    |  | |   |HttpSession          | 
    |  | |   |hssn-9541A863A42B7294412DF27003FE67BF associated| 
    |  | |   |with SipApplicationSession      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo     | 
    |-----------------------------------------------------------------------| 
    |00029|0000|02:18:47 AM|SipApplicationSession       | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo associated with | 
    |  | |   |Tropo session a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |-----------------------------------------------------------------------| 
    |00030|0000|02:18:47 AM|customerName:Kent is added into the context of | 
    |  | |   |app instance : ApplicationInstance[myURL,  | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo]     | 
    |-----------------------------------------------------------------------| 
    |00031|0000|02:18:47 AM|numberToDial:20874is added into the  | 
    |  | |   |context of app instance : ApplicationInstance[ | 
    |  | |   |myURL , sas_2-14-sm86gosslpnlz6tropo]   | 
    |-----------------------------------------------------------------------| 
    |00032|0000|02:18:47 AM|action:create is added into the context of app | 
    |  | |   |instance : ApplicationInstance[myURL ,   | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo]     | 
    |-----------------------------------------------------------------------| 
    |00033|0000|02:18:47 AM|format:xml is added into the context of app | 
    |  | |   |instance : ApplicationInstance[myURL ,   | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo]     | 
    |-----------------------------------------------------------------------| 
    |00034|0000|02:18:47 AM|msg:XML Test is added into the context of app | 
    |  | |   |instance : ApplicationInstance[myURL ,   | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo]     | 
    |-----------------------------------------------------------------------| 
    |00035|0000|02:18:47 AM|ApplicationInstance[myURL ,      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo] has been created. | 
    |-----------------------------------------------------------------------| 
    |00036|0000|02:18:47 AM|[email protected] | 
    |  | |   |is added into the context of app instance :  | 
    |  | |   |ApplicationInstance[myURL ,      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo]     | 
    |-----------------------------------------------------------------------| 
    |00037|0000|02:18:47 AM|Clearing logging context for     | 
    |  | |   |http/0.0.0.0/8080-t-31       | 
    |-----------------------------------------------------------------------| 
    |00038|0000|02:18:47 AM|Set logging context for       | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |  | |   |to accountID=107029 host=tropo203.orl.voxeo.net | 
    |  | |   |sessionGUID=0         | 
    |  | |   |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |  | |   |callID=-1          | 
    |-----------------------------------------------------------------------| 
    |00039|0000|02:18:47 AM|ApplicationInstance[myURL ,      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo] starts execution | 
    |  | |   |on Thread          | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |-----------------------------------------------------------------------| 
    |00040|0000|02:18:47 AM|Thread           | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |  | |   |acquired engine QuercusScriptEngine[] of type | 
    |  | |   |php, activeEngines = 5       | 
    |-----------------------------------------------------------------------| 
    |00041|0000|02:18:47 AM|ApplicationInstance[myURL ,      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo] replaced script | 
    |  | |   |engine [QuercusScriptEngine[]] -->    | 
    |  | |   |[QuercusScriptEngine[]] in field <_engine>  | 
    |-----------------------------------------------------------------------| 
    |00042|0000|02:18:47 AM|ApplicationInstance[myURL ,      | 
    |  | |   |sas_2-14-sm86gosslpnlz6tropo] ends execution on | 
    |  | |   |Thread           | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |-----------------------------------------------------------------------| 
    |00043|0000|02:18:47 AM|Thread           | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |  | |   |returned engine QuercusScriptEngine[] of type | 
    |  | |   |php, activeEngines = 4       | 
    |-----------------------------------------------------------------------| 
    |00044|0000|02:18:47 AM|sas_2-14-sm86gosslpnlz6tropo invalidated  | 
    |-----------------------------------------------------------------------| 
    |00045|0000|02:18:47 AM|Instance a8f0ba032d2a377e8fdcc8b68d82c766  | 
    |  | |   |removed           | 
    |-----------------------------------------------------------------------| 
    |00046|0000|02:18:47 AM|Clearing logging context for     | 
    |  | |   |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 | 
    |-----------------------------------------------------------------------| 

回答

3

它看起来像这里也有困惑/问题的几个点,所以我会尽我最大努力解决他们都是为了你。我想讨论的第一件事是,将会话API的XML帖子完全是可选的,它只是一种可以提交'令牌请求'来启动呼出呼叫的方法。如果您在得到这个工作的问题,让我们跳过它,并尝试'平面简HTTP从浏览器直接拨打,直到你最舒服:

api.tropo.com/1.0/sessions?action=create&token=123456&customerName=Kent&numberToDial=4075551212&msg=XML%20Test 

现在到脚本本身,我发现你accountID(是的,我工作在Voxeo Labs/Tropo:P),我注意到了一些事情。首先,你拼错了应用程序startURL,我几乎肯定你的意思是ExternalPhoneHelper.php,但是你键入了ExterMalPhoneHelper.php,所以你需要先解决这个问题。现在第二件事,你的文件实际上是空白的,除了PHP标签。

所以,如果你想拨打电话,说一些你可以使用call();用say();或者你可以使用组合/快捷方式消息();您的对流层脚本中的方法:

<?php 
message("Received office voice mail.", array("to" => "+14075550100")); 
?> 

现在到了最后一个问题,你如何在对流层应用程序上下文您发布的数据?好了,好消息是,这是死的简单,我们实际上这些范围为在应用程序全局的,所以numberToDial查询字符串参数变为$ numberToDial,例如:

<?php 
message($msg, array("to" => "+".$numberToDial)); 
?> 

我真的希望这会有所帮助,如果你仍然发现自己遇到了麻烦,碰到了我们的支持团队,或者在freenode(#tropo)的IRC上找到我们。我的手柄是染色机,而且我经常在潜伏的通道中;)

保重!

-John

+0

这是我需要的解决方案。我没有意识到XML变量的范围是全局变量!我只需要这样做: <?php call($ numberToDial); 说($味精); ?> 感谢您的帮助! – objectivesea 2012-01-03 03:34:40