使用 AMI(与 Asteriskserver 的 API 连接,因此我可以使用 PHP 套接字连接)我正在尝试使用 PHP 捕获接收数据,以便我可以记录用于 CRM 系统(基于 Web)的传出和传入调用我工作的公司。但我没有得到我希望的结果......完整的代码可以在 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 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}
任何人都可以帮助我吗?授权数据是正确的(它在整个脚本中使用相同的数据并且确实获得了连接)。此外,我没有收到响应“操作:Ping ???...”,它说脚本作为命令发送,但是三个问号和句点来自哪里?