1

我有简单的 AGI 脚本,当接听来电时运行脚本。但不工作。如何正确运行我的脚本?

顺便说一句对不起我的英语。

这是代码:

extensions_additional.conf

[macro-auto-blkvm]

include => macro-auto-blkvm-custom

exten => s,1,Set(__MACRO_RESULT=)    
exten => s,n,DBDel(${BLKVM_OVERRIDE})

exten => s,n,AGI(call-answered.agi,${CALLERID(ANI)},${CHANNEL})   

call-answered.php:

#!/usr/bin/php -q
<?php
include("phpagi.php");
$agi = new AGI();
$agi->verbose("------------------------------------------");
$ani = $agi->request['agi_callerid'];
$agi->noop("My CalleID: <<<<<<<=".$ani);

$user = 'root';
$pass = 'eLaStIx.2oo7';
$db = new PDO('mysql:host=localhost;dbname=call', $user, $pass);

$query = $db->prepare("INSERT INTO deneme SET
gsm = ?,
agent = ?");
$insert = $query->execute(array("123123", "213123"));

控制台输出:

-- SIP/103-0000000e answered Local/103@from-internal-3556,2
-- Executing [s@macro-auto-blkvm:1] Set("SIP/103-0000000e", "__MACRO_RESULT=") in new stack
-- Executing [s@macro-auto-blkvm:2] Set("SIP/103-0000000e", "CFIGNORE=") in new stack
-- Executing [s@macro-auto-blkvm:3] Set("SIP/103-0000000e", "MASTER_CHANNEL(CFIGNORE)=") in new stack
-- Executing [s@macro-auto-blkvm:4] Set("SIP/103-0000000e", "FORWARD_CONTEXT=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:5] Set("SIP/103-0000000e", "MASTER_CHANNEL(FORWARD_CONTEXT)=from-internal") in new stack
-- Executing [s@macro-auto-blkvm:6] Macro("SIP/103-0000000e", "blkvm-clr|") in new stack
-- Executing [s@macro-auto-blkvm:7] AGI("SIP/103-0000000e", "call-answered.agi|*******|SIP/103-0000000e") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/call-answered.agi
AGI Tx >> agi_request: call-answered.agi
AGI Tx >> agi_channel: SIP/103-0000000e
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1481798039.22
AGI Tx >> agi_callerid: 103
AGI Tx >> agi_calleridname: unknown
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: unknown
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: macro-auto-blkvm
AGI Tx >> agi_extension: s
AGI Tx >> agi_priority: 7
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
-- AGI Script call-answered.agi completed, returning 0
-- Executing [s@macro-auto-blkvm:8] ExecIf("SIP/103-0000000e", "0?Set(MASTER_CHANNEL(CONNECTEDLINE(num))=103)") in new stack
== Spawn extension (macro-auto-blkvm, s, 8) exited non-zero on 'SIP/103-0000000e' in macro 'auto-blkvm'
-- Local/103@from-internal-3556,1 answered SIP/103-0000000d
-- Stopped music on hold on SIP/**-0000000d

谢谢

4

2 回答 2

2

你确定你命名了你的文件call-answered.php吗?您在拨号计划中将其称为call-answered.agi,这看起来不一致。尝试将拨号方案更改为call-answered.php.

检查 .php 文件是否具有读取和执行文件权限。运行chmod 755 /var/lib/asterisk/agi-bin/*.php设置。

还要检查它们是否位于正确的目录中(默认为 /var/lib/asterisk/agi-bin),或在您的拨号计划中指定完整路径。将其放在引号中以确保安全:

exten => s,n,AGI('/var/lib/asterisk/agi-bin/call-answered.php',${CALLERID(ANI)},${CHANNEL})

您可以在官方 AGI 文档Voip 信息(非官方)页面上找到更多帮助。

编辑: 您还可以尝试通过运行以下命令直接从 PHP cli 运行脚本:

php /var/lib/asterisk/agi-bin/call-answered.php

反复按 enter 以模拟与 Asterisk 的通信。如果有任何权限或脚本错误,您通常会在此 cli 会话中看到这些错误。如果这仍然不起作用,请使用 php 的error_log()命令将一些有用的信息写入日志,这样您就可以判断您的脚本是否正在运行。

于 2016-12-30T03:43:30.993 回答
-2

这意味着您的脚本中有语法错误或权限问题。或者可能只是路径上没有脚本。

即它根本没有反应。

于 2016-12-16T21:30:39.157 回答