从拨号方案到AGI脚本的星号服务器传递变量

时间:2012-07-12 09:01:58

标签: php asterisk asteriskami agi

我的拨号方案就像这样

[dial-plan]
exten => s,1,Answer()
exten => s,n,Noop(exten = ${EXTEN}
exten => s,n,Macro(dumpvars)
exten => s,n,Macro(record-enable)
exten => s,n,AGI(success.php)
exten => i,1,Noop(REASON = ${REASON})
exten => i,n,Macro(dumpvars)
exten => i,n,AGI(faile.php)
exten => failed,1,Noop(REASON = ${REASON})
exten => failed,n,Macro(dumpvars)
exten => failed,n,AGI(faile.php)

我想从faile.php调用的地方捕获,可以从failedi调用。我该如何检查

我需要这样做是faile.php

if($some_var == 1){
     //Invalid
}
elsif($some_var == 2){
    //Failed
}

5 个答案:

答案 0 :(得分:1)

将使用一些标准参数调用agi,包括被叫扩展(在您的情况下,将是ifailed)。确保您正在解析传递给脚本的参数(通过stdin)!

答案 1 :(得分:0)

在脚本中使用phpagi.php,它为AGI提供所有必需的解析。

或者查看http://www.voip-info.org/wiki/view/Asterisk+AGI+php

上的示例

答案 2 :(得分:0)

如果我正确理解了您的问题,您需要将变量传递给PHP AGI脚本。 这是如何做到的:

exten => i,n,AGI(faile.php,invalid)

exten => failed,n,AGI(faile.php,failed)

然后,您的PHP AGI脚本应如下所示:

#!/usr/bin/php -q
<?php
set_time_limit(30);
//load PHP AGI
require('phpagi/phpagi.php');
error_reporting(E_ALL);
$agi = new AGI();

$status = $argv[1];

if($status == "invalid")
{
  // invalid
} else
{ 
  // failed
}
?>

答案 3 :(得分:0)

以下是我与php-agi.php

实现相同的方法

failed.php(如果呼叫失败将执行)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $astman->set_variable('CallState','failed');

?>

success.php(如果调用成功将执行)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $astman->set_variable('CallState','success');

?>

hangup.php(如果呼叫失败或成功,将在呼叫结束时执行)

<?php
    require_once "phpagi.php";
    require_once "phpagi-asmanager.php";

    $astman = new AGI();
    $call_state = agi_get_var('CallState');
    if($call_state == "success"){
        //call was success
    }
    elseif($call_state == "failed"){
        //call was failed
    }
?>

答案 4 :(得分:0)

在Dialplan中

exten => _*999*.,1,Answer()
exten => _*999*.,n,Set(var1=1) 
exten => _*999*.,n,AGI(test.php,${var1})

在php

<?php
    require('phpagi.php');

    $agi = new AGI();

    $agi->say_digit($argv[1]);

    $agi->hangup();
?>