简体   繁体   English

java / php连接到星号服务器

[英]java/php connecting to the asterisk server

我想问问是否可以在Asterisk服务器中连接php代码/ java脚本...。请某人回答我的问题,我非常感谢您的回答...请帮助我...并给我一些代码或步骤如何做到...预先感谢

You can interface with AMI by using PHP: AMI PHP Examples . 您可以使用PHP与AMI交互: AMI PHP示例 As far as some sample code, you can fire PHP script from jquery/javascript using an ajax call. 至于一些示例代码,您可以使用ajax调用从jquery / javascript触发PHP脚本。 Here is a sample script I wrote to rick roll friends, just POST a 10 digit phone number to it and it calls the phone number and plays 'never gonna give you up'. 这是我写给rick roll朋友的示例脚本,只需在其中张贴一个10位数的电话号码,它就会拨打该电话号码并播放“永不放弃”。 This PHP script also assumes that its hosted on the same server that your asterisk instance is hosted on, you can change the $strHost if it's not. 此PHP脚本还假定其托管在您的星号实例所在的同一服务器上,如果没有,您可以更改$ strHost。

PHP Script: 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');
     }

Then you'll need to add the something like the following to your extensions.conf to tell asterisk what to do with the call: 然后,您需要在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

I hope that helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM