简体   繁体   中英

Trouble getting Asterisk AMI click2call working

I've setup an Asterisk AMI-based click2call extension for Chrome to test out, but it refuses to do anything when I send it a number.

If I plug http://10.8.0.2/amiscript.php?phone=5555555555&exten=910 right into my browser, I just get Please enter a number to dial. right back. It doesn't seem to be interpreting the number correctly.

Link to the extension: http://bitree.ru/click2call4chrome_en.html

I'm using the PHP script example, obviously. And based on it giving me an error back, I assume everything is good on my web server end. Here's the script:

<? if (!empty( $_REQUEST['phone'])   && !empty( $_REQUEST['exten']  ) )
{
        $num = $_REQUEST['phone'];
        $ext = $_REQUEST['exten'];
        $num = preg_replace( "/^\+7/", "8", $num );
        $num = preg_replace( "/\D/", "", $num );

        if ( ! empty( $num ) )
        {
                echo "Dialing $num\r\n";

                $timeout = 10;
                $asterisk_ip = "127.0.0.1";

                $socket = fsockopen($asterisk_ip,"5038", $errno, $errstr, $timeout);
                fputs($socket, "Action: Login\r\n");
                fputs($socket, "UserName: bitree\r\n");
                fputs($socket, "Secret: bitree_secret\r\n\r\n");

                $wrets=fgets($socket,128);

                echo $wrets;

                fputs($socket, "Action: Originate\r\n" );
                fputs($socket, "Channel: Local/$ext@from-internal\r\n" );
                fputs($socket, "Exten: $num\r\n" );
                fputs($socket, "Context: from-internal\r\n" );
                fputs($socket, "Priority: 1\r\n" );
                fputs($socket, "Async: yes\r\n" );
                fputs($socket, "WaitTime: 15\r\n" );
                fputs($socket, "Callerid: $num\r\n\r\n" );

                $wrets=fgets($socket,128);
                echo $wrets;
        }
        else
        {
                echo "Unable to determine number from (" . $_REQUEST['phone'] . ")\r\n";
        }
}
else
{?>Please enter a number to dial.
<?}?>

Any suggestions?

First of all, there are more then 1 realisation of AMI protocol(full) in php.

For example phpagi/phpami.

It already stable and work ok.

Also i can recommend you do output of variables you get.

Simplest method is add at start of your php code something like

print_r($_REQUEST);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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