📄 phpagi.php
字号:
* @param string $message
* @param integer $level from 1 to 4
* @return array, see evaluate for return information.
*/
function verbose($message, $level=1)
{
foreach(explode("\n", str_replace("\r\n", "\n", print_r($message, true))) as $msg)
{
@syslog(LOG_WARNING, $msg);
$ret = $this->evaluate("VERBOSE \"$msg\" $level");
}
return $ret;
}
/**
* Waits up to $timeout milliseconds for channel to receive a DTMF digit.
*
* @link http://www.voip-info.org/wiki-wait+for+digit
* @param integer $timeout in millisecons. Use -1 for the timeout value if you want the call to wait indefinitely.
* @return array, see evaluate for return information. ['result'] is 0 if wait completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function wait_for_digit($timeout=-1)
{
return $this->evaluate("WAIT FOR DIGIT $timeout");
}
// *********************************************************************************************************
// ** APPLICATIONS **
// *********************************************************************************************************
/**
* Set absolute maximum time of call.
*
* Note that the timeout is set from the current time forward, not counting the number of seconds the call has already been up.
* Each time you call AbsoluteTimeout(), all previous absolute timeouts are cancelled.
* Will return the call to the T extension so that you can playback an explanatory note to the calling party (the called party
* will not hear that)
*
* @link http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands
* @link http://www.dynx.net/ASTERISK/AGI/ccard/agi-ccard.agi
* @param $seconds allowed, 0 disables timeout
* @return array, see evaluate for return information.
*/
function exec_absolutetimeout($seconds=0)
{
return $this->exec('AbsoluteTimeout', $seconds);
}
/**
* Executes an AGI compliant application.
*
* @param string $command
* @return array, see evaluate for return information. ['result'] is -1 on hangup or if application requested hangup, or 0 on non-hangup exit.
* @param string $args
*/
function exec_agi($command, $args)
{
return $this->exec("AGI $command", $args);
}
/**
* Set Language.
*
* @param string $language code
* @return array, see evaluate for return information.
*/
function exec_setlanguage($language='en')
{
return $this->exec('SetLanguage', $language);
}
/**
* Do ENUM Lookup.
*
* Note: to retrieve the result, use
* get_variable('ENUM');
*
* @param $exten
* @return array, see evaluate for return information.
*/
function exec_enumlookup($exten)
{
return $this->exec('EnumLookup', $exten);
}
/**
* Dial.
*
* Dial takes input from ${VXML_URL} to send XML Url to Cisco 7960
* Dial takes input from ${ALERT_INFO} to set ring cadence for Cisco phones
* Dial returns ${CAUSECODE}: If the dial failed, this is the errormessage.
* Dial returns ${DIALSTATUS}: Text code returning status of last dial attempt.
*
* @link http://www.voip-info.org/wiki-Asterisk+cmd+Dial
* @param string $type
* @param string $identifier
* @param integer $timeout
* @param string $options
* @param string $url
* @return array, see evaluate for return information.
*/
function exec_dial($type, $identifier, $timeout=NULL, $options=NULL, $url=NULL)
{
return $this->exec('Dial', trim("$type/$identifier|$timeout|$options|$url", '|'));
}
/**
* Goto.
*
* This function takes three arguments: context,extension, and priority, but the leading arguments
* are optional, not the trailing arguments. Thuse goto($z) sets the priority to $z.
*
* @param string $a
* @param string $b;
* @param string $c;
* @return array, see evaluate for return information.
*/
function exec_goto($a, $b=NULL, $c=NULL)
{
return $this->exec('Goto', trim("$a|$b|$c", '|'));
}
// *********************************************************************************************************
// ** FAST PASSING **
// *********************************************************************************************************
/**
* Say the given digit string, returning early if any of the given DTMF escape digits are received on the channel.
* Return early if $buffer is adequate for request.
*
* @link http://www.voip-info.org/wiki-say+digits
* @param string $buffer
* @param integer $digits
* @param string $escape_digits
* @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function fastpass_say_digits(&$buffer, $digits, $escape_digits='')
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->say_digits($digits, $escape_digits);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}));
}
/**
* Say the given number, returning early if any of the given DTMF escape digits are received on the channel.
* Return early if $buffer is adequate for request.
*
* @link http://www.voip-info.org/wiki-say+number
* @param string $buffer
* @param integer $number
* @param string $escape_digits
* @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function fastpass_say_number(&$buffer, $number, $escape_digits='')
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->say_number($number, $escape_digits);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}));
}
/**
* Say the given character string, returning early if any of the given DTMF escape digits are received on the channel.
* Return early if $buffer is adequate for request.
*
* @link http://www.voip-info.org/wiki-say+phonetic
* @param string $buffer
* @param string $text
* @param string $escape_digits
* @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function fastpass_say_phonetic(&$buffer, $text, $escape_digits='')
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->say_phonetic($text, $escape_digits);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}));
}
/**
* Say a given time, returning early if any of the given DTMF escape digits are received on the channel.
* Return early if $buffer is adequate for request.
*
* @link http://www.voip-info.org/wiki-say+time
* @param string $buffer
* @param integer $time number of seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC).
* @param string $escape_digits
* @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function fastpass_say_time(&$buffer, $time=NULL, $escape_digits='')
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->say_time($time, $escape_digits);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}));
}
/**
* Play the given audio file, allowing playback to be interrupted by a DTMF digit. This command is similar to the GET DATA
* command but this command returns after the first DTMF digit has been pressed while GET DATA can accumulated any number of
* digits before returning.
* Return early if $buffer is adequate for request.
*
* @link http://www.voip-info.org/wiki-stream+file
* @param string $buffer
* @param string $filename without extension, often in /var/lib/asterisk/sounds
* @param string $escape_digits
* @param integer $offset
* @return array, see evaluate for return information. ['result'] is -1 on hangup or error, 0 if playback completes with no
* digit received, otherwise a decimal value of the DTMF tone. Use chr() to convert to ASCII.
*/
function fastpass_stream_file(&$buffer, $filename, $escape_digits='', $offset=0)
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->stream_file($filename, $escape_digits, $offset);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0);
}
/**
* Use festival to read text.
* Return early if $buffer is adequate for request.
*
* @link http://www.cstr.ed.ac.uk/projects/festival/
* @param string $buffer
* @param string $text
* @param string $escape_digits
* @param integer $frequency
* @return array, see evaluate for return information.
*/
function fastpass_text2wav(&$buffer, $text, $escape_digits='', $frequency=8000)
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->text2wav($text, $escape_digits, $frequency);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0);
}
/**
* Use Cepstral Swift to read text.
* Return early if $buffer is adequate for request.
*
* @link http://www.cepstral.com/
* @param string $buffer
* @param string $text
* @param string $escape_digits
* @param integer $frequency
* @return array, see evaluate for return information.
*/
function fastpass_swift(&$buffer, $text, $escape_digits='', $frequency=8000, $voice=NULL)
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
{
if(!strpos(chr(255) . $escape_digits, $buffer{strlen($buffer)-1}))
$proceed = true;
}
if($buffer == '' || $proceed)
{
$res = $this->swift($text, $escape_digits, $frequency, $voice);
if($res['code'] == AGIRES_OK && $res['result'] > 0)
$buffer .= chr($res['result']);
return $res;
}
return array('code'=>AGIRES_OK, 'result'=>ord($buffer{strlen($buffer)-1}), 'endpos'=>0);
}
/**
* Say Puncutation in a string.
* Return early if $buffer is adequate for request.
*
* @param string $buffer
* @param string $text
* @param string $escape_digits
* @param integer $frequency
* @return array, see evaluate for return information.
*/
function fastpass_say_punctuation(&$buffer, $text, $escape_digits='', $frequency=8000)
{
$proceed = false;
if($escape_digits != '' && $buffer != '')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -