我有一个简单的AGI脚本,我需要通过拨打6666号码来拨打101分机,并计算通话后的应答时间。当被叫方挂断时,一切正常,但是当被叫方挂断agi脚本返回4时,一切正常。
对不起我的英语不好)
agi.php
#!/usr/bin/php -q
<?php
require('include/phpagi.php');
$agi = new AGI();
$agi->answer();
$agi->exec("Dial", "SIP/101");
$result = $agi->get_variable("ANSWEREDTIME");
file_put_contents("/tmp/test.txt", json_encode($result));
$agi->hangup();
?>
[general]
externaddr=51.15.53.237:5060
localnet=10.18.222.53/255.255.255.0 ; локальная сеть
language=ru
context=default
allowoverlap=no
udpbindaddr=0.0.0.0
tcpenable=no
tcpbindaddr=0.0.0.0
transport=udp
srvlookup=yes
allowguest=no
limitonpeers=yes
[authentication]
[managers-phones](!)
type=friend
context=call-out
secret=qwerty
host=dynamic
nat=yes
qualify=yes
canreinvite=no
callgroup=1
pickupgroup=1
call-limit=5
dtmfmode=auto
disallow=all
allow=alaw
allow=ulaw
allow=g729
allow=g723
allow=g722
[100](managers-phones)
callerid="Number 100" <100>
[101](managers-phones)
callerid="Number 101" <101>
[general]
static=yes
writeprotect=no
[globals]
[default]
[handup-sip]
exten => _X!,1,HangUp()
[call-out]
exten => 6666,1,AGI(agi.php)
exten => _XXX,1,Dial(SIP/${EXTEN})
include => handup-sip
== Using SIP RTP CoS mark 5
> 0x7fabe000deb0 -- Strict RTP learning after remote address set to: 176.213.58.47:7078
-- Executing [6666@call-out:1] AGI("SIP/100-00000016", "agi.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/agi.php
<SIP/100-00000016>AGI Tx >> agi_request: agi.php
<SIP/100-00000016>AGI Tx >> agi_channel: SIP/100-00000016
<SIP/100-00000016>AGI Tx >> agi_language: ru
<SIP/100-00000016>AGI Tx >> agi_type: SIP
<SIP/100-00000016>AGI Tx >> agi_uniqueid: 1594145722.33
<SIP/100-00000016>AGI Tx >> agi_version: 16.11.1
<SIP/100-00000016>AGI Tx >> agi_callerid: 100
<SIP/100-00000016>AGI Tx >> agi_calleridname: Number 100
<SIP/100-00000016>AGI Tx >> agi_callingpres: 0
<SIP/100-00000016>AGI Tx >> agi_callingani2: 0
<SIP/100-00000016>AGI Tx >> agi_callington: 0
<SIP/100-00000016>AGI Tx >> agi_callingtns: 0
<SIP/100-00000016>AGI Tx >> agi_dnid: 6666
<SIP/100-00000016>AGI Tx >> agi_rdnis: unknown
<SIP/100-00000016>AGI Tx >> agi_context: call-out
<SIP/100-00000016>AGI Tx >> agi_extension: 6666
<SIP/100-00000016>AGI Tx >> agi_priority: 1
<SIP/100-00000016>AGI Tx >> agi_enhanced: 0.0
<SIP/100-00000016>AGI Tx >> agi_accountcode:
<SIP/100-00000016>AGI Tx >> agi_threadid: 140374906681088
<SIP/100-00000016>AGI Tx >>
<SIP/100-00000016>AGI Rx << ANSWER
> 0x7fabe000deb0 -- Strict RTP switching to RTP target address 176.213.58.47:7078 as source
<SIP/100-00000016>AGI Tx >> 200 result=0
<SIP/100-00000016>AGI Rx << EXEC Dial SIP/101
-- AGI Script Executing Application: (Dial) Options: (SIP/101)
== Using SIP RTP CoS mark 5
-- Called SIP/101
-- SIP/101-00000017 is ringing
> 0x7fabd000cb70 -- Strict RTP learning after remote address set to: 176.213.58.47:8000
-- SIP/101-00000017 answered SIP/100-00000016
-- Channel SIP/101-00000017 joined 'simple_bridge' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
-- Channel SIP/100-00000016 joined 'simple_bridge' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
> Bridge dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b: switching from simple_bridge technology to native_rtp
> Locally RTP bridged 'SIP/100-00000016' and 'SIP/101-00000017' in stack
> 0x7fabd000cb70 -- Strict RTP switching to RTP target address 176.213.58.47:8000 as source
> 0x7fabe000deb0 -- Strict RTP learning complete - Locking on source address 176.213.58.47:7078
-- Channel SIP/101-00000017 left 'native_rtp' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
-- Channel SIP/100-00000016 left 'native_rtp' basic-bridge <dafb98ba-3e18-4c2e-a51c-46f2f7cc7f5b>
<SIP/100-00000016>AGI Tx >> 200 result=-1
<SIP/100-00000016>AGI Rx << GET VARIABLE ANSWEREDTIME
<SIP/100-00000016>AGI Tx >> 200 result=1 (6)
<SIP/100-00000016>AGI Rx << HANGUP
<SIP/100-00000016>AGI Tx >> 200 result=1
-- <SIP/100-00000016>AGI Script agi.php completed, returning 4
== Spawn extension (call-out, 6666, 1) exited non-zero on 'SIP/100-00000016'
== Using SIP RTP CoS mark 5
> 0x7fabe000deb0 -- Strict RTP learning after remote address set to: 176.213.58.47:7078
-- Executing [6666@call-out:1] AGI("SIP/100-0000001e", "agi.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/agi.php
<SIP/100-0000001e>AGI Tx >> agi_request: agi.php
<SIP/100-0000001e>AGI Tx >> agi_channel: SIP/100-0000001e
<SIP/100-0000001e>AGI Tx >> agi_language: ru
<SIP/100-0000001e>AGI Tx >> agi_type: SIP
<SIP/100-0000001e>AGI Tx >> agi_uniqueid: 1594145890.45
<SIP/100-0000001e>AGI Tx >> agi_version: 16.11.1
<SIP/100-0000001e>AGI Tx >> agi_callerid: 100
<SIP/100-0000001e>AGI Tx >> agi_calleridname: Number 100
<SIP/100-0000001e>AGI Tx >> agi_callingpres: 0
<SIP/100-0000001e>AGI Tx >> agi_callingani2: 0
<SIP/100-0000001e>AGI Tx >> agi_callington: 0
<SIP/100-0000001e>AGI Tx >> agi_callingtns: 0
<SIP/100-0000001e>AGI Tx >> agi_dnid: 6666
<SIP/100-0000001e>AGI Tx >> agi_rdnis: unknown
<SIP/100-0000001e>AGI Tx >> agi_context: call-out
<SIP/100-0000001e>AGI Tx >> agi_extension: 6666
<SIP/100-0000001e>AGI Tx >> agi_priority: 1
<SIP/100-0000001e>AGI Tx >> agi_enhanced: 0.0
<SIP/100-0000001e>AGI Tx >> agi_accountcode:
<SIP/100-0000001e>AGI Tx >> agi_threadid: 140374906681088
<SIP/100-0000001e>AGI Tx >>
<SIP/100-0000001e>AGI Rx << ANSWER
> 0x7fabe000deb0 -- Strict RTP switching to RTP target address 176.213.58.47:7078 as source
<SIP/100-0000001e>AGI Tx >> 200 result=0
<SIP/100-0000001e>AGI Rx << EXEC Dial SIP/101
-- AGI Script Executing Application: (Dial) Options: (SIP/101)
== Using SIP RTP CoS mark 5
-- Called SIP/101
-- SIP/101-0000001f is ringing
> 0x7fac0000c120 -- Strict RTP learning after remote address set to: 176.213.58.47:8000
-- SIP/101-0000001f answered SIP/100-0000001e
-- Channel SIP/101-0000001f joined 'simple_bridge' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
-- Channel SIP/100-0000001e joined 'simple_bridge' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
> Bridge e8f305f8-5d84-4ae7-8be5-babcdefdb5ef: switching from simple_bridge technology to native_rtp
> Locally RTP bridged 'SIP/100-0000001e' and 'SIP/101-0000001f' in stack
> 0x7fac0000c120 -- Strict RTP switching to RTP target address 176.213.58.47:8000 as source
-- Channel SIP/101-0000001f left 'native_rtp' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
-- Channel SIP/100-0000001e left 'native_rtp' basic-bridge <e8f305f8-5d84-4ae7-8be5-babcdefdb5ef>
<SIP/100-0000001e>AGI Tx >> 200 result=-1
<SIP/100-0000001e>AGI Rx << GET VARIABLE ANSWEREDTIME
<SIP/100-0000001e>AGI Tx >> 200 result=1 (4)
<SIP/100-0000001e>AGI Rx << HANGUP
<SIP/100-0000001e>AGI Tx >> 200 result=1
-- <SIP/100-0000001e>AGI Script agi.php completed, returning 4
== Spawn extension (call-out, 6666, 1) exited non-zero on 'SIP/100-0000001e'
答案 0 :(得分:0)
我不知道您到底需要做什么,但是如果您想在调用发生后再获取一些数据,我认为正确的方法是运行挂断脚本。查看挂断脚本的工作原理-h扩展和挂断处理程序:
https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers
在您的情况下,您仍然尝试在无效通道上执行某些操作,这是不正确的方法。