From: sleepy Date: Tue, 28 Apr 2020 09:39:30 +0000 (+1000) Subject: AGI исправлены мелкие ошибки X-Git-Url: http://git.ultra-x.su/?a=commitdiff_plain;h=e0dd2b4d62a3a4793da4ab1a129b211696ac622a;p=dev AGI исправлены мелкие ошибки --- diff --git a/astapilib/agi.php b/astapilib/agi.php index 98ecfbd..58e80de 100644 --- a/astapilib/agi.php +++ b/astapilib/agi.php @@ -249,7 +249,7 @@ trait funcAGI } //Stream file, prompt for DTMF, with timeout. - public function GetOption ($file, $escape_digits, $timeout = NULL) + public function GetOption ($file, $escape_digits = '', $timeout = NULL) { $timeout = $timeout * 1000; $params = $this->make_params(get_defined_vars()); @@ -266,7 +266,7 @@ trait funcAGI } //Sends audio file on channel. - public function StreamFile ($filename, $escape_digits, $sample_offset = NULL) + public function StreamFile ($filename, $escape_digits = '', $sample_offset = NULL) { $params = $this->make_params(get_defined_vars()); $cmd = 'stream file'; @@ -316,7 +316,7 @@ trait funcAGI } //Records to a given file. - public function RecordFile ($filename, $format, $escape_digits, $timeout = -1, $offset_samples = NULL, $BEEP = NULL, $silence = NULL) + public function RecordFile ($filename, $format, $escape_digits = '', $timeout = -1, $offset_samples = NULL, $BEEP = NULL, $silence = NULL) { if ($timeout != -1) { @@ -574,7 +574,7 @@ trait funcAGI } //Sends audio file on channel and allows the listener to control the stream. - public function ControlStreamFile ($filename, $escape_digits, $skipms = NULL, $ffchar = NULL, $rewchr = NULL, $pausechr = NULL, $offsetms = NULL) + public function ControlStreamFile ($filename, $escape_digits = '', $skipms = NULL, $ffchar = NULL, $rewchr = NULL, $pausechr = NULL, $offsetms = NULL) { $params = $this->make_params(get_defined_vars()); $cmd = 'control stream file'; diff --git a/check_code.php b/check_code.php index de6edb3..8ec6b1b 100644 --- a/check_code.php +++ b/check_code.php @@ -1,15 +1,19 @@ '; +$RETRYCALL = 3; +$INTERVAL = 5; +// +//test data echo "
\n";
-$_GET['phone'] = 3400;
+$_GET['phone'] = '3400';
 var_dump($_GET);
+
 if (!isset($_GET['phone']))
 {
     exit();
@@ -18,8 +22,28 @@ if(preg_match('/^7\d{10}$/', $_GET['phone']) != 1)
 {
     //exit();
 }
+//generate random pin
+$PIN = [];
+for ($cnt = 0; $cnt < $PINLEN;$cnt++)
+{
+    mt_srand(str_replace('.', '', (string)array_product(sys_getloadavg())) * crc32(microtime()));
+    $cnte = mt_rand(0,30);
+    $cntr = 0;
+    do
+    {
+	$rnd = mt_rand(0,9);
+	$cntr++;
+    }
+    while($cntr < $cnte);
+    $PIN[] = $rnd;
+    usleep(mt_rand(1,250000));
+}
+
+echo implode('', $PIN),PHP_EOL;
 
-$AMI = new AMI(array('autorefresh' => TRUE, 'logverbose' => 6));
+//fork point
+
+$AMI = new AMI(array('autorefresh' => TRUE, 'logverbose' => 3));
 $is_connected = $AMI->connect("127.0.0.1", "monast", "blabla");
 
 if (!$is_connected)
@@ -27,23 +51,37 @@ if (!$is_connected)
     exit();
 }
 
-$OriginateResponce = $AMI->Originate("Local/{$_GET['phone']}@c-2", NULL, NULL, NULL, 'AGI', 'agi:async', 30, 3500, NULL, NULL, NULL, NULL);
-$OriginateResponce->WaitUntilReady();
+for ($tryno = 0; $tryno < $RETRYCALL;$tryno++)
+{
+    $OriginateResponce = $AMI->Originate("Local/{$_GET['phone']}@c-2", NULL, NULL, NULL, 'AGI', 'agi:async', 30, $CALLFROM, ['CALLERID(ANI-num)' => '3505'], NULL, NULL, NULL);
+    $OriginateResponce->WaitUntilReady();
+    if ($OriginateResponce->Response == 'Success')
+    {
+	break;
+    }
+    sleep($INTERVAL);
+}
+if ($OriginateResponce->Response != 'Success')
+{
+    exit();
+}
 $channel = $OriginateResponce->Channel;
-var_dump($AMI->GetAsyncAGIChannelList());
 $AGI = $AMI->GetAsyncAGIInstance($channel);
-//$AGI = new AGI();
-echo '------------------';
-var_dump($AGI->GetVariable('CALLERID(num)'));
-var_dump($AGI->GetVariable('CALLERID(name)'));
-
-echo '------------------';
-var_dump($AGI->SayDigits('012345'));
-var_dump($AGI->Hangup());
-unset($AGI);
-sleep(5);
-while (TRUE)
+
+for ($tryno = 0; $tryno < $REPEATNO;$tryno++)
 {
-    sleep(1);
-    echo '+';
-}
\ No newline at end of file
+    $AGI->StreamFile('your');
+    $AGI->StreamFile('parol');
+    foreach ($PIN as $digit)
+    {
+	if (!$AGI->IsAlive())
+	{
+	    break 2;
+	}
+	$AGI->SayDigits($digit);
+	usleep(500000);
+    }
+    sleep(2);
+}
+$AGI->Hangup();
+unset($AGI);