Re: Проблема с ExternalIVR()
Добавлено: 05 апр 2011, 12:43
Сделал дамп, обнаружен один звонок. Включаю плеер, звука нет маркер стоит на одном месте. Что дальше?
ded писал(а):Невозможно побуквенно передавать "Войну и мир" азбукой Морзе.
Код: Выделить всё
#!/usr/bin/perl -w
use Asterisk::AGI;
use WWW::Curl::easy;
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
$AGI->setcallback(\&mycallback);
# print STDERR "AGI Environment Dump:\n";
#
# foreach $i (sort keys %input) {
# print STDERR "-- $i = $input{$i}\n";
# }
my $userid = $input{'calleridname'};
my $exten = $input{'extension'};
open(fileOUT, ">>/var/log/asterisk/calls.log");
$logtime = gmtime(time);
print fileOUT "-----------\n";
print fileOUT "[$logtime]:Userid -> $userid\n";
if($exten eq 'h') {
$exten = "User hangup";
print fileOUT "[$logtime]:Dialed Digits -> $exten\n";
print fileOUT "-----------\n";
close(fileOUT);
exit;
}
else {
print fileOUT "[$logtime]:Dialed Digits -> $exten\n";
print fileOUT "-----------\n";
close(fileOUT);
}
if($exten eq '1000') {
$AGI->verbose("User wants IVR - So we give it to them!");
$AGI->verbose("Dialing to give IVR to enter a PIN!");
$AGI->set_callerid("1000");
$AGI->exec("Dial", "Zap/g1/003211111111");
exit 1;
}
my ($sth, $query);
[DB Information Removed]
$attempts = 0;
use Mysql;
$dbh = Mysql->connect($DBHost, $DBDatabase, $DBUser, $DBPassword);
HandleError( "System", "Fatal", "DBConnectFail", *Data,
"Unable to create connection to database: $error" )
if( $error = Mysql->errmsg );
$query = "select * from associations where userid = '$userid'";
$sth = $dbh->query( $query );
if($sth->numrows < 1) {
$AGI->verbose("Dialing to give IVR to enter a PIN!");
$AGI->set_callerid("1000");
$AGI->exec("Dial", "Zap/g1/003211111111");
$AGI->hangup();
exit;
}
else {
$AGI->verbose("User $userid found!\n");
@fetched = $sth->FetchRow;
my($MAC, $PIN, $acc_code, $id, $datetime, $active) = @fetched;
if($exten == "*99") { # User wants to change their PIN
&get_pin($acc_code, $id, $MAC);
}
elsif($PIN == "" || $active == 0) {
&get_pin($acc_code, $id, $MAC);
}
else {
$callerid = "$acc_code"."#$PIN";
$AGI->verbose("Callerid : $callerid");
$AGI->set_callerid($callerid);
#$AGI->set_callerid("1000");
$AGI->verbose("Dialing $exten\n");
$AGI->exec("Dial", "Zap/g1/003211111111");
#$AGI->exec("Dial", "Zap/g1/***01");
#$AGI->exec("Dial", "Zap/g1/003211111111");
exit;
}
}
sub mycallback {
my ($returncode) = @_;
print STDERR "CALLBACK: User Hangup ($returncode)\n";
exit($returncode);
}
sub get_pin($$$) {
$account_code = $_[0];
$userid = $_[1];
$MAC = $_[2];
$attempts++;
if($attempts eq 3) {
$AGI->exec("Playback", "thank-you-for-calling");
sleep(1);
$AGI->exec("Playback", "goodbye");
sleep(1);
$AGI->hangup();
exit 1;
}
$AGI->exec("Playback","please-enter-your");
$AGI->exec("Playback","card-number");
my $pin= $AGI->get_data("then-press-pound", "10000", "13");
$AGI->exec('Playback', 'you-entered');
$AGI->say_digits($pin);
$AGI->exec('Playback', 'if-correct-press');
$AGI->exec('SayNumber','1');
$AGI->exec('Playback', 'otherwise-press');
$AGI->exec('SayNumber','2');
my $correct= $AGI->get_data("then-press-pound", "10000", "2");
if($correct eq 1) {
$AGI->exec("Playback","auth-thankyou");
my $return_code = &validate_pin($pin, $account_code, $userid, $MAC);
$AGI->verbose("Return code: $return_code\n");
if($return_code eq 100) {
# $query = "update associations set PIN = '$pin' where userid =
'$userid' and MAC = '$MAC'";
# $stah = $dbh->query($query);
$AGI->exec("Playback", "pin-number-accepted");
$AGI->hangup();
}
}
else {
$attempts = $attempts - 1; # Don't count this attempt against them
&get_pin($account_code, $userid, $MAC);
}
}
sub validate_pin($$$$) {
$pin = $_[0];
$account_code = $_[1];
$userid = $_[2];
$MAC = $_[3];
$url = [removed];
$postfields = "Service=Validate&PIN=$pin";
$rawdata = "";
&post_data($url, $postfields);
if($rawdata =~ m/true/) {
$return_code = "100";
return $return_code;
}
else {
$AGI->exec("Playback", "pin-number-invalid");
$AGI->exec("Playback", "pls-try-again");
&get_pin($account_code, $userid, $MAC);
}
}
sub post_data($$) {
$url = $_[0];
$postfields = $_[1];
print STDERR "$url\n$postfields\n";
my $curl = Curl::easy::init();
if(!$curl) {
die "curl init failed!\n";
}
$::errbuf = "";
WWW::Curl::easy::setopt($curl, CURLOPT_ERRORBUFFER, "::errbuf");
WWW::Curl::easy::setopt($curl, CURLOPT_URL, $url);
WWW::Curl::easy::setopt($curl, CURLOPT_NOPROGRESS, 1);
WWW::Curl::easy::setopt($curl, CURLOPT_TIMEOUT, 30);
WWW::Curl::easy::setopt($curl, CURLOPT_HEADERFUNCTION,
\&header_callb);
WWW::Curl::easy::setopt($curl, CURLOPT_WRITEFUNCTION, \&body_callb);
WWW::Curl::easy::setopt($curl, CURLOPT_POST, 1);
WWW::Curl::easy::setopt($curl, CURLOPT_POSTFIELDS,$postfields);
WWW::Curl::easy::setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
WWW::Curl::easy::setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
WWW::Curl::easy::setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
WWW::Curl::easy::setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0");
WWW::Curl::easy::perform($curl);
WWW::Curl::easy::cleanup($curl);
}
sub body_callb {
my($chunk,$handle)[EMAIL PROTECTED];
${handle} .= $chunk;
$rawdata .= $chunk;
print STDERR $chunk;
return length($chunk);
}
sub header_callb {
return length($_[0]);
}
Код: Выделить всё
my $pin= $AGI->get_data("then-press-pound", "10000", "13");