PHP AMI 连接 - 将传入和传出呼叫保存到数据库不起作用

发布于 2024-11-07 04:15:49 字数 3371 浏览 1 评论 0原文

使用 AMI(与 Asteriskserver 的 API 连接,以便我可以使用 PHP 套接字连接),我尝试使用 PHP 捕获接收数据,以便我可以记录 CRM 系统(基于网络)的传出和传入呼叫我工作的公司。 但我没有得到我希望的结果...... 完整的代码可以在 PasteBin http://pastebin.com/AwRNBW2G 上找到,

我用这种方式接出电话,并且有效:

  if($givenkey = array_search("Context: from-internal", $content)){
            $calleridKey = $givenkey + 1;
            $idSIP = $givenkey - 1;
            $dialNumber = str_replace("Extension: 0","31",$content[$calleridKey]);
            $dialNumber = str_replace("Extension: ", "", $dialNumber);
            $fromSIP = str_replace("Channel: SIP/", "", $content[$idSIP]);
            $fromSIP = substr($fromSIP, 0, 2);
            $dialTime = date('r');

            $uitgaand = array(
                            "Phonenumber"   => $dialNumber,
                            "Type"          => "Uitgaand",
                            "datetime"      => $dialTime,
                            "SIP"           => $fromSIP
                            );

正在以这种方式捕获传入呼叫,但这无法正常工作:

   if($givenkey = array_search("AppData: Using CallerID ", $content)){
            if(array_search("Channel: SIP/31000000000", $content)+5 == $InCallKey = array_search("AppData: Using CallerID", $content)){
                    $calleridNum = explode('"',str_replace('AppData: Using CallerID "',"",$content[$InCallKey]));
                    $pickupSource = array_search("Source: SIP/31000000000", $content);
                    if($pickupSource+1 == $pickupKey = array_search("Destination: SIP/", $content)){
                            $pickupBy =  str_replace("Destination: SIP/","",$content[$pickupkey]);
                            $pickupBy = substr($pickupBy, 0, 2);
                            $dialTime = date('r');         
                            $inkomend = array(
                                            "Phonenumber" => $calleridNum[0],
                                            "Type"          => "Binnenkomend",
                                            "datetime"      => $dialTime,
                                            "SIP"           => $pickupBy
                                            );

我现在无法使用该数组,但如果有必要,我可以保存该数组并将其与个人数据一起发布到此处过滤。

我知道我现在使用的代码并不整洁,但我编写它的目标是:快速获得结果。如果我有一个工作代码,我会优化它并清理它。对此的提示也非常受欢迎。很遗憾我找不到任何关于此的好的文档,所以我必须从头开始,只能找到我现在正在使用的工作类,但它不是很完整。 我必须在没有任何有关 VOIP、AMI 或 Asterisk 知识的情况下编写这部分内容。

简而言之,这是我的问题: - 如何使用 AMI 记录传入和传出呼叫并最终将其保存在数据库中? - 如何以最佳方式保持与服务器的连接?我现在使用的方法不是最佳的,因为连接在 48 小时内至少失败一次。 - 您对优化代码和更整洁的代码编写有什么建议或建议吗?您是否知道我可以使用哪些函数来代替我正在使用的函数?

就此而言, 登普西

最近我收到这个错误 我无法正确解决。这个错误 大约 15 分钟后自行创建 跑步。它将运行至少 24 小时 之前:

PHP 注意:fwrite():发送 16 个字节失败,errno=32 第 147 行 /var/www/html/phpami/AMILoader.php 中的管道损坏
Net_AsteriskManagerException:/var/www/html/phpami/AMILoader.php 第 173 行授权失败
#0 /var/www/html/phpami/AMILoader.php(173): Net_AsteriskManager-login('GEBRUIKERSNAAM','WACHTWOORD')
#1 /var/www/html/phpami/AMILoader.php(306): Net_AsteriskManager-_sendCommand('操作:Ping???...')
#2 /var/www/html/phpami/AMILoader.php(543): Net_AsteriskManager->ping()
#3 {主要}

任何人都可以帮我解决这个问题吗?这 授权数据正确(是 整体使用相同的数据 脚本,它确实获得了连接)。 我也没有得到回应“行动: Ping???...' 它说的是 通过脚本作为命令发送,但是 三个问号在哪里 经期从何而来?

Using the AMI (API connection with an Asteriskserver so I can use a PHP Socket connection) I'm trying to catch the recieving data using PHP in a way that I can record outgoing and incomming calls for the CRM system (webbased) used at the company I work for.
But I'm not getting the result I am hoping for...
The full code can be found on PasteBin http://pastebin.com/AwRNBW2G

I catch the outgoing calls this way, and that works:

  if($givenkey = array_search("Context: from-internal", $content)){
            $calleridKey = $givenkey + 1;
            $idSIP = $givenkey - 1;
            $dialNumber = str_replace("Extension: 0","31",$content[$calleridKey]);
            $dialNumber = str_replace("Extension: ", "", $dialNumber);
            $fromSIP = str_replace("Channel: SIP/", "", $content[$idSIP]);
            $fromSIP = substr($fromSIP, 0, 2);
            $dialTime = date('r');

            $uitgaand = array(
                            "Phonenumber"   => $dialNumber,
                            "Type"          => "Uitgaand",
                            "datetime"      => $dialTime,
                            "SIP"           => $fromSIP
                            );

The incomming calls are being catched this way, but that's not working properly:

   if($givenkey = array_search("AppData: Using CallerID ", $content)){
            if(array_search("Channel: SIP/31000000000", $content)+5 == $InCallKey = array_search("AppData: Using CallerID", $content)){
                    $calleridNum = explode('"',str_replace('AppData: Using CallerID "',"",$content[$InCallKey]));
                    $pickupSource = array_search("Source: SIP/31000000000", $content);
                    if($pickupSource+1 == $pickupKey = array_search("Destination: SIP/", $content)){
                            $pickupBy =  str_replace("Destination: SIP/","",$content[$pickupkey]);
                            $pickupBy = substr($pickupBy, 0, 2);
                            $dialTime = date('r');         
                            $inkomend = array(
                                            "Phonenumber" => $calleridNum[0],
                                            "Type"          => "Binnenkomend",
                                            "datetime"      => $dialTime,
                                            "SIP"           => $pickupBy
                                            );

I have the array that I make not available right now but, if necessary, I can save the array and post it here with personal data filtered.

I know that the code I'm using right now is not neat, but I wrote it with the goal: quick result. If I have a working code I will optimize it and clean it up. Tips about this are also very welcome. It's too bad that I cannot find any good documentation about this so I have to start from the beginning and could only find the working class that I'm using right now, however it's not very complete.
I had to write this part without any knowledge about VOIP or AMI or Asterisk.

To be short, here are my questions:
- How can I record incoming and outgoing calls to eventually save them in a database by using the AMI?
- How can I keep alive the connection with the server the best way? The method I'm using now is not optimal as the connection fails atleast once within 48 hours.
- Do you have tips or suggestions about optimizing the code and neater code-writing? And do you maybe know any functions that I could use instead of a function that I am using?

With regards,
Dempsey

Since recently I get this error which
I cannot solve properly. This error
creates itself after about 15 minutes
running. It would run atleast 24 hours
before:

PHP Notice:  fwrite(): send of 16 bytes failed with errno=32 Broken pipe in /var/www/html/phpami/AMILoader.php on line 147
Net_AsteriskManagerException: Authorisation failed in /var/www/html/phpami/AMILoader.php on line 173
#0 /var/www/html/phpami/AMILoader.php(173): Net_AsteriskManager-login('GEBRUIKERSNAAM','WACHTWOORD')
#1 /var/www/html/phpami/AMILoader.php(306): Net_AsteriskManager-_sendCommand('Action: Ping???...')
#2 /var/www/html/phpami/AMILoader.php(543): Net_AsteriskManager->ping()
#3 {main}

Can anyone help me with this too? The
authorisation data is correct (it is
using the same data in the whole
script and it does get a connection).
Also I don't get the response 'Action:
Ping???...' which it says is being
send by the script as command, but
where do the three questionmarks and
periods come from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海的爱人是光 2024-11-14 04:15:49

这个框架应该很方便:
https://github.com/marcelog/PAMI

否则您可以检查 vTiger 源代码以及它如何处理 ami 集成:
http://www.vtiger.com /index.php?Itemid=57&id=30&option=com_content&task=view

this framework should be handy:
https://github.com/marcelog/PAMI

otherwise you can check vTiger sources and how it handles ami integration:
http://www.vtiger.com/index.php?Itemid=57&id=30&option=com_content&task=view

倦话 2024-11-14 04:15:49

如果您使用 php,连接 AMI 最简单的方法之一是使用 php-astmanager 类。它支持某些“事件”的回调,以便您可以捕获所需的数据。最好的(唯一?)维护的副本是 FreePBX 的一部分,可以直接从最新版本(2.9 作为写这篇文章)。

If your using php, one of the easiest way to connect to the AMI is using the php-astmanager class. It supports callback on certain "events" so that you can catch the data you need. The best (only?) maintained copy is part of FreePBX and can be pulled right out of the latest version (2.9 as of this writing).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文