我想问一下是否有可能在Asterisk服务器上连接php代码/ java脚本.... plz有人回答我的问题我非常感谢你的回答...请帮助我...并给我一些代码或步骤如何制作...提前感谢
答案 0 :(得分:1)
您可以使用PHP:AMI PHP Examples与AMI进行交互。对于一些示例代码,您可以使用ajax调用从jquery / javascript触发PHP脚本。这是我写给rick roll朋友的一个示例脚本,只是发一个10位数的电话号码给它,它拨打电话号码然后播放'永远不会放弃你'。此PHP脚本还假定它托管在托管星号实例的同一服务器上,如果不是,则可以更改$ strHost。
PHP脚本:
#now some variables are assigned to connect to asterisk
$strHost = "127.0.0.1";
$strUser = "yourusername";
$strSecret = "yourpassword";
$strWaitTime = "30";
$strPriority = "1";
$strMaxRetry = "2";
#get the value from the form in rickroll.php
$strExten = $_POST['txtphonenumber'];
#some asterisk CLI debugging stuff
$callNumber = $strExten;
$strCallerId = "RICKROLL <$callNumber>";
#get the length of our input (giggity)
$length = strlen($strExten);
#check to make sure the input value is at least 10
#digits, if true, send the information to
#the "rickroll" context that is setup in extensions_custom.conf
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: Local/1$callNumber@from-internal\r\n");
fputs($oSocket, "WaitTime: $strWaitTime\r\n");
fputs($oSocket, "CallerId: $strCallerId\r\n");
fputs($oSocket, "Exten: s\r\n");
fputs($oSocket, "Context: rickroll\r\n");
fputs($oSocket, "Priority: 1\r\n\r\n");
fputs($oSocket, "Action: Logoff\r\n\r\n");
sleep(3);
fclose($oSocket);
}
//else tell them how to do it correctly
else
{
echo ('Please enter a 10 digit number and try again');
}
然后你需要在extensions.conf中添加如下内容,告诉星号如何处理这个调用:
[rickroll]
exten => s,1,NoOp(inizio) ; verbose
exten => s,n,Answer
exten => s,n(message),Background(rickroll) ; "play rickroll.mp3 located in n/var/lib/asterisk/sounds/"
exten => s,n,WaitExten(5)
exten => t,1,Playback(vm-goodbye)
exten => t,2,Hangup
我希望有所帮助。