我是 Asterisk (VoIP) 的新手,对 UNIX/Perl 还是比较陌生。我从一个离开公司的同事那里接手这个,所以我一开始没有设置这个,我只需要做一些改变。
我遇到了一个问题,我使用 get_data() 来获取用户的键盘输入,但是键被忽略并且 get_data() 函数只是超时。我一直试图缩小它发生的确切时间,但每次我认为我已经把它缩小到“它只发生在我......”时,我再试一次,它就起作用了。这个问题可能发生在大约 75% 的时间里,而且由于我缺乏使用 Asterisk 的经验,我不知道是什么原因造成的。
下面是我测试并重现问题的代码的摘录。在“thankyouforcalling”文件以$demoFlag = $AGI->get_data("demoFlag", 10000, 1);
. 有谁知道是什么原因造成的?谢谢!
基本的.pl:
#!/usr/bin/perl
use Asterisk::AGI;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $loop, $env, $demoFlag, $user_id, $password, $type, $mac;
@types = ("", "u", "s");
@environments = ("prod", "test");
($seconds, $minutes, $hours, $day, $month, $year) = localtime();
$year += 1900;
$month += 1;
$date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hours, $minutes, $seconds);
$AGI->verbose("Call Received from ". $input{'callerid'} ." ${date}");
$lrepeat = 1;
while ($lrepeat == 1)
{
$env = 0;
$AGI->stream_file('thankyouforcalling');
do
{
$loop = 0;
$demoFlag = $AGI->get_data("demoFlag", 10000, 1); # 1 = yes, 2 = no
if ($demoFlag != 1 && $demoFlag != 2)
{
$AGI->stream_file("invalidKey");
$loop = 1;
}
} while ($loop);
if ($demoFlag == 2)
{
do
{
$loop = 0;
$user_id = $AGI->get_data("userid", 10000, 6);
if (length($user_id) != 6)
{
$AGI->stream_file("invalidEntry");
$loop = 1;
}
} while ($loop);
do
{
$loop = 0;
$password = $AGI->get_data("password", 10000, 6);
if (length($password) != 6)
{
$AGI->stream_file("invalidEntry");
$loop = 1;
}
} while ($loop);
}
do
{
$loop = 0;
$type = $AGI->get_data("type", 10000, 1); # 1 = UNIQUE, 2 = SERIAL
if ($type != 1 && $type != 2)
{
$AGI->stream_file("invalidKey");
$loop = 1;
}
} while ($loop);
do
{
$loop = 0;
my $file;
if ($type == 1) { $file = "uniqueID"; }
else { $file = "serial" }
$mac = $AGI->get_data($file, 10000, 6);
if (length($mac) != 6)
{
$AGI->stream_file("invalidEntry");
$loop = 1;
}
} while ($loop);
$lrepeat = 0;
}
$AGI->stream_file('greatAgreatday');
$AGI->hangup();
exit(0);