使用Originate的出站呼叫上的星号callerid在agi_dnid

时间:2019-07-07 09:33:41

标签: asterisk

我添加了一个自定义PHP文件,以将所有出站呼叫记录到我的MySQL数据库中。 当我从任何分机拨号时,并且记录呼叫者ID和目的地号码等时,此方法均有效。

但是,当我运行一个独立的PHP脚本从应用程序发起呼叫时。 呼叫者ID和拨打的号码现在未知。

nano /var/lib/asterisk/agi-bin/logoutbound.php

#!/usr/bin/php -q
<?php
include("phpagi.php");
$agi = new AGI();


//$agi->noop("test 1");
$servername = "servername";
$username = "username";
$password = "pass";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$mycallerid = $agi->request[agi_callerid];
$mycallername = $agi->request[agi_calleridname];
$phoneno = $agi->request['agi_dnid'];
$myuniid = $agi->request[agi_uniqueid];
$timestart = date('Y-m-d H-i-s');
$channel = $agi->request[agi_channel];
$extension = $agi->request[agi_extension];
$context = $agi->request[agi_context];


$sql = "INSERT INTO voip_outbound
(callerid,callername,uniid,starttime,phonenumber,channel,extension,context)
VALUES ('" . $mycallerid . "','$mycallername','$myuniid','$timestart','$phoneno','$channel','$extension','$context'$

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}


$conn->close();
?>

此文件被称为 nano extensions_custom.conf

[macro-dialout-trunk-predial-hook]
exten => s,1,Noop(Custom outbound call)
exten => s,n,AGI(logoutbound.php)

所以当我拨出时,我的MySQL中得到以下内容。而且这是正确的

image from mysql database

参考30 + 32显示从分机拨打的电话。 Refid 31显示使用原始脚本进行的呼叫-见下文

<?php
error_reporting(0);
#ip address that asterisk is on.
$strHost = "127.0.0.1";
$strUser = "admin";#specify the asterisk manager username you want to login with
$strSecret = "managerpass";#specify the password for the above user
#specify the channel (extension) you want to receive the call requests with
#e.g. SIP/XXX, IAX2/XXXX, ZAP/XXXX, etc
# $strChannel = "SIP/100";
$strChannel = $_REQUEST['exten'];
$strContext = "from-internal";
#specify the amount of time you want to try calling the specified channel     before hangin up
$strWaitTime = "30";
#specify the priority you wish to place on making this call
$strPriority = "1";
#specify the maximum amount of retries
$strMaxRetry = "2";
$number=strtolower($_REQUEST['number']);
$pos=strpos ($number,"local");
if ($number == null) :
exit() ;  
endif ;
if ($pos===false) :
$errno=0 ;
$errstr=0 ;
$strCallerId = "$number";
#$strCallerId = "$strChannel";
$oSocket = fsockopen ("localhost", 5038, $errno, $errstr, 20);
if (!$oSocket) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($oSocket, "Action: login\r\n");
fputs($oSocket, "Events: off\r\n");
fputs($oSocket, "Username: $strUser\r\n");
fputs($oSocket, "Secret: $strSecret\r\n\r\n");
fputs($oSocket, "Action: originate\r\n");
fputs($oSocket, "Channel: $strChannel\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
#fputs($oSocket, "CallerId: $strCallerId <$strCallerId>\r\n");
fputs($oSocket, "CallerId: $number\r\n");
fputs($oSocket, "Exten: $number\r\n");
fputs($oSocket, "Context: $strContext\r\n");
fputs($oSocket, "Priority: $strPriority\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
sleep(2);
fclose($oSocket);
} 
echo "Extension $strChannel should be calling $number." ;
else :
exit() ;
endif ;
?>

所以我的预期结果是显示所拨打的号码,而不是未知的 我将如何解决此问题以显示正确的信息?

也许我应该从另一个宏或其他东西调用文件。

感谢您的帮助

EDIT:根据我的脚本更改为loca后,注释已更改。 因此,以PJSIP的Local / 1069 insead的身份发送到我的扩展程序中,我仍然在我的mysql中得到它

enter image description here

1 个答案:

答案 0 :(得分:0)

在您的示例中,callerid未知。

Callerid NAME未知。

您可以尝试使用

Callerid: "name" <number>

如果没有帮助,请使用本地渠道并设置(CALLERID(name)=

关于freepbx报表中的DST参数-如果要设置,请使用Local / num @ ext-local。