我如何知道呼叫的状态 - Asterisk 和 PHP?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2315744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:00:28  来源:igfitidea点击:

How can I know the status of a call - Asterisk and PHP?

phpvoipasterisk

提问by Harph

I'm developing an application with PHP and a Asterisk Server. One of the features of the application is to check the call status (ringing, answered, hung...) of an specific caller ID, so I would like to know how to do this, because I'm trying with a socket and the command status but I think it has to be a better way to do it.

我正在使用 PHP 和 Asterisk 服务器开发应用程序。该应用程序的功能之一是检查特定来电显示的呼叫状态(振铃、接听、挂断...),所以我想知道如何执行此操作,因为我正在尝试使用套接字和命令状态,但我认为它必须是一种更好的方法。

Thanks in advance.

提前致谢。

回答by rdegges

What API are you using to write this program? AMI? AGI? FastAGI? DeadAGI? Call files? There's a lot of ways to get this information.

你用什么 API 来编写这个程序?阿米?通用电气?快速AGI?死AGI?调用文件?有很多方法可以获取这些信息。

NOTE: You cannot tell if a channel has been hungup unless you are using call files and/or CDR access.

注意:除非您使用呼叫文件和/或 CDR 访问,否则您无法判断频道是否已挂断。

With the AMI, you can use the Status command (documented here: http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Status).

对于 AMI,您可以使用 Status 命令(记录在此处:http: //www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Status)。

With the AGI, you will know the status as it is determined by your program. If you are still in your AGI script, then the call is still in progress and already answered.

使用 AGI,您将了解由您的程序确定的状态。如果您仍在 AGI 脚本中,则呼叫仍在进行中并且已经应答。

If you are using call files, and you have the Archive attribute set to 'yes', then once the call has completed then you can check your outoing_done directory (typically /var/lib/asterisk/outgoing_done/) for your call file. When you read the callfile, you'll notice that Asterisk has appended a status at the bottom of the call file, which will tell you the final status of the call.

如果您正在使用呼叫文件,并且您将存档属性设置为“是”,那么一旦呼叫完成,您就可以检查您的 outoing_done 目录(通常是 /var/lib/asterisk/outgoing_done/)以获取您的呼叫文件。当你阅读调用文件时,你会注意到 Asterisk 在调用文件的底部附加了一个状态,它会告诉你调用的最终状态。

The BESTway to get this information is by having your PHP script read from the CDR records on your Asterisk server. Have your CDR records log to a MySQL database, then pull records for your call from the database.

获得此信息的最佳方法是让您的 PHP 脚本从您的 Asterisk 服务器上的 CDR 记录中读取。将您的 CDR 记录记录到 MySQL 数据库中,然后从数据库中提取您的呼叫记录。

回答by Seaux

Harph,

哈夫,

You can create an AMI daemon to listen to AMI events streamed from Asterisk. I've done this many times, one of those being for the Asterisk GUI. If you create a table for status in your database, you can create a daemon to listen to the AMI events and update the status as they happen. Then your webpage won't have to interact with Asterisk at all, it'll just need to read the status from the database.

您可以创建一个 AMI 守护进程来监听从 Asterisk 流式传输的 AMI 事件。我已经做过很多次了,其中之一是针对 Asterisk GUI。如果您在数据库中为状态创建一个表,您可以创建一个守护进程来监听 AMI 事件并在它们发生时更新状态。这样你的网页就完全不需要与 Asterisk 交互了,它只需要从数据库中读取状态。

The following link is from the Asterisk GUI project. It is written in javascript, so your php would be a little different, but this will give you a good base to start with. Start with line 574.

以下链接来自 Asterisk GUI 项目。它是用 javascript 编写的,所以你的 php 会有点不同,但这会给你一个很好的基础。从第 574 行开始。

http://svn.asterisk.org/view/asterisk-gui/branches/2.0/config/js/welcome.js?view=markup

http://svn.asterisk.org/view/asterisk-gui/branches/2.0/config/js/welcome.js?view=markup

One of the key differences in javascript vs php is that javascript has to use Asterisk's http daemon instead of a socket connection straight to AMI. Because of this it has to use the 'waitevent' stuff. But since you'll be using a TCP socket connection, just keep looping a read statement.

javascript 与 php 的主要区别之一是 javascript 必须使用 Asterisk 的 http 守护程序,而不是直接连接到 AMI 的套接字连接。因此,它必须使用“waitevent”的东西。但是由于您将使用 TCP 套接字连接,因此只需继续循环读取语句。

Hope this helps! This method seems to be the most reliable when trying to get information from Asterisk.

希望这可以帮助!当试图从 Asterisk 获取信息时,这种方法似乎是最可靠的。

回答by DrClue

I actually use HTML5 webSockets and AsterClick ,a middleware daemon I wrote in PHP.

我实际上使用 HTML5 webSockets 和 AsterClick,这是我用 PHP 编写的中间件守护程序。

AsterClick is , as far as I know ,the only truly event drivenAsterisk AMI interface for HTML5 on the planet. All the other solutions out there are still stuck polling the server.

据我所知,AsterClick 是地球上唯一真正的事件驱动的Asterisk AMI 接口 HTML5。所有其他解决方案仍然无询服务器。

I can watch the status of calls in real time, originate . transfer between (queues,meetme,parking,individuals) simply by drag-n-drop in my browser. I can create functioning ad hoc dialplan entries without writing to the dialplan or basically anything else Asterisk AMI can do with NO POLLINGever.

我可以实时查看呼叫状态,发起。只需在浏览器中拖放即可在(队列、聚会、停车、个人)之间转移。我可以创建功能正常的临时拨号计划条目,而无需写入拨号计划或基本上任何 Asterisk AMI 可以在没有轮询的情况下做的事情。

In Javascript I can use an addEventListener() function that actually takes the names of AMI events as parameters. There is NO POLLING, but rather when the Asterisk AMI emits an event it is sent to my browser over the webSocket generating an event which processes the data and emits more events within the browser.

在 Javascript 中,我可以使用 addEventListener() 函数,该函数实际上将 AMI 事件的名称作为参数。有没有轮询,而是当Asterisk的AMI发出一个事件将被发送到我的浏览器通过WebSocket的产生,其处理浏览器内的数据,并发出更多事件的事件。

I also have a tool called WBEA that allows me to deploy those same HTML5 AsterClick applications as stand alone desktop executables for Windows and Linux.

我还有一个名为 WBEA 的工具,它允许我将这些相同的 HTML5 AsterClick 应用程序部署为 Windows 和 Linux 的独立桌面可执行文件。

回答by Arun Unnikrishnan

I use CLI command to check channel status.Here is the php code I use

我使用 CLI 命令来检查频道状态。这是我使用的 php 代码

<?php 
    $socket = fsockopen("111.11.11.111",$portno, $errno, $errstr, $timeout);
    fputs($socket, "Action: Login\r\n");
    fputs($socket, "UserName: username\r\n");
    fputs($socket, "Secret: secret\r\n\r\n");


     $channel=$_GET['value']; //pass channel through GET method


    echo"<pre>";
    fwrite($socket, "Action: Status\r\n");
    fwrite($socket, "Command: Lists channel status ".$channel."\r\n\r\n");
    $wrets="";


    fputs($socket, "Action: Logoff\r\n\r\n");

    while (!feof($socket)) {
      $wrets .= fread($socket, 8192).'</br>';
    }

    echo $wrets."<br/>";

    fclose($socket);    

    ?>