从asterisk agi执行ajax调用

时间:2015-01-12 05:21:27

标签: php jquery ajax asterisk agi

我有一个网络服务,它接受电话号码和用户输入的号码。我想通过ajax调用执行这个web服务,我可以在其中传递详细信息,ajax调用的结果将播放给用户。

但我不知道如何通过星号执行ajax调用。可能我们需要' AGI',我试过,但失败了。

Extension.conf

exten => s,1,Answer()
exten => s,n,agi(googletts.agi,"Welcome to System. Please enter your number.",en)   
exten => s,n,agi(a.php)
exten => s,n,WaitExten()

我试图通过php做到这一点,但即使我的PHP脚本也没有执行。

a.php只会

#!/usr/bin/php -q 
<?
ob_implicit_flush(false); 
set_time_limit(6);

$stdin = fopen(‘php://stdin’, ‘r’);
$stdlog = fopen(‘my_agi.log’, ‘w’);
SayDigits(6)
$debug = true;

/* Read input from Asterisk and output via $astOutput */
function astRead() 
{ 
 global $stdin, $debug, $stdlog; 
  $astOutput = str_replace("n", "", fgets($stdin, 4096)); 
  if ($debug) fputs($stdlog, "read: $inputn"); 
  return $astOutput ; 
} 


/* Write AGI command to Asterisk */
function astWrite($agiCommand) 
{ 
  global $debug, $stdlog; 
  if ($debug) fputs($stdlog, "write: $agiCommandn"); 
  echo $agiCommand."n"; 
}

/* Handling execution input from Asterisk */
$agivar = array();
while (!feof($stdin)) 
{ 
 $temp = fgets($stdin); 
 $temp = str_replace("n","",$temp); 
 $s = explode(":",$temp); 
 $agivar[$s[0]] = trim($s[1]); 
 if ($temp == "")  
 { 
    break; 
 } 
}

/* Operational Code starts here */

/* Playback the demo-congrats.gsm file from the
* directory /var/lib/asterisk/sounds/ 
*/

astWrite("STREAM FILE demo-congrats #");
astRead();

/* Say the number 123456 */
astWrite("SAY NUMBER 123456 #");
astRead();

/* Finalization of AGI script and clean-ups */

fclose ($stdin);
fclose ($stdlog);
exit(0);

?>

0 个答案:

没有答案