首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当调用者挂断时,星号AGI脚本会下降。

当调用者挂断时,星号AGI脚本会下降。
EN

Stack Overflow用户
提问于 2020-07-07 18:23:02
回答 1查看 1.6K关注 0票数 0

我有一个简单的AGI脚本,我需要拨打101分机,拨打6666号码,并在呼叫后计算应答时间。当被调用者挂断时,一切正常,但是当调用者挂断agi脚本时,返回4就会掉下来。

对不起我的英语)

agi.php

代码语言:javascript
复制
#!/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();
?>

**sip.conf**

代码语言:javascript
复制
[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>

**extensions.conf**

代码语言:javascript
复制
[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

当被调用者挂断时控制台输出:

代码语言:javascript
复制
== 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'

呼叫者挂断时控制台输出:

代码语言:javascript
复制
== 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'

因此,当调用者挂断时,就没有文件/tmp/test.txt,而在被调用方挂机时就有了。问题在哪里?星号16 LTS来自于源PHP 7.2.24-0ubuntu0.18.04.6

EN

回答 1

Stack Overflow用户

发布于 2020-07-08 14:25:38

我不知道您到底需要做什么,但是如果您在调用发生后想要一些数据,我认为正确的方法是运行挂起脚本。查看挂起脚本是如何工作的-h扩展和挂起处理程序:

https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

在您的情况下,您仍在尝试在死胡同上做一些不正确的方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62781626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档