Hi,
I am Nitin (Sr. PHP Developer)
I have installed asterisk and freePBX on our local server and now we want call to our customer by asterisk and pbx by php api. I have implemented api for calling but Outgoing call working but voice communication not working please see below sample code.
Click2Dial <?phpstrName = isset(_POST[‘txtname’])?$_POST[‘txtname’]:’’;
strExten = isset(_POST[‘txtphonenumber’])?$_POST[‘txtphonenumber’]:’’;
$callNumber = $strExten;
$strHost = “127.0.0.1”;
$strUser = “xxxx”;
$strSecret = “xxxxxxxxxxxxxxxxxxxxx”;
$strChannel = “local/$callNumber@from-internal”;
$strContext = “from-internal”;
$strWaitTime = “300”;
$strPriority = “1”;
$strMaxRetry = “2”;
#--------------------------------------------------------------------------------------------
#Shouldn’t need to edit anything below this point to make this script work
#--------------------------------------------------------------------------------------------
#specify the caller id for the call
$strCallerId = “Web-”.$strName . " <$callNumber>";
$length = strlen($strExten);
if ($length == 10 && is_numeric($strExten))
{
$oSocket = fsockopen($strHost, ‘5038’, $errnum, $errdesc) or die(“Connection to host failed”);
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\r\n”);
fputs($oSocket, “Exten: 1001\r\n”);
fputs($oSocket, “Context: $strContext\r\n”);
fputs($oSocket, “Priority: 1\r\n\r\n”);
fputs($oSocket, “Action: Logoff\r\n\r\n”);
sleep(3);
while ($wrets=fgets($oSocket)) {
var_dump($wrets);
}
fclose($oSocket);
?>
We are processing your call, please wait about two minutes. If you have not received our call within two minutes, verify that your name and number were entered correctly and try again. |
Go Back
<?php } else { ?>
Enter your name and 10-digit number (e.g. 7875551234). If available, we will call you within the next two minutes.
Name: Number: |