📄 phpagi-asmanager.php
字号:
* Mailbox: <mailboxid>
* NewMessages: <count>
* OldMessages: <count>
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
* @param string $actionid message matching variable
*/
function MailboxCount($mailbox, $actionid=NULL)
{
$parameters = array('Mailbox'=>$mailbox);
if($actionid) $parameters['ActionID'] = $actionid;
return $this->send_request('MailboxCount', $parameters);
}
/**
* Check Mailbox
*
* Returns number of messages.
* Message: Mailbox Status
* Mailbox: <mailboxid>
* Waiting: <count>
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus
* @param string $mailbox Full mailbox ID <mailbox>@<vm-context>
* @param string $actionid message matching variable
*/
function MailboxStatus($mailbox, $actionid=NULL)
{
$parameters = array('Mailbox'=>$mailbox);
if($actionid) $parameters['ActionID'] = $actionid;
return $this->send_request('MailboxStatus', $parameters);
}
/**
* Monitor a channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor
* @param string $channel
* @param string $file
* @param string $format
* @param boolean $mix
*/
function Monitor($channel, $file=NULL, $format=NULL, $mix=NULL)
{
$parameters = array('Channel'=>$channel);
if($file) $parameters['File'] = $file;
if($format) $parameters['Format'] = $format;
if(!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false';
return $this->send_request('Monitor', $parameters);
}
/**
* Originate Call
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate
* @param string $channel Channel name to call
* @param string $exten Extension to use (requires 'Context' and 'Priority')
* @param string $context Context to use (requires 'Exten' and 'Priority')
* @param string $priority Priority to use (requires 'Exten' and 'Context')
* @param string $application Application to use
* @param string $data Data to use (requires 'Application')
* @param integer $timeout How long to wait for call to be answered (in ms)
* @param string $callerid Caller ID to be set on the outgoing channel
* @param string $variable Channel variable to set (VAR1=value1|VAR2=value2)
* @param string $account Account code
* @param boolean $async true fast origination
* @param string $actionid message matching variable
*/
function Originate($channel,
$exten=NULL, $context=NULL, $priority=NULL,
$application=NULL, $data=NULL,
$timeout=NULL, $callerid=NULL, $variable=NULL, $account=NULL, $async=NULL, $actionid=NULL)
{
$parameters = array('Channel'=>$channel);
if($exten) $parameters['Exten'] = $exten;
if($context) $parameters['Context'] = $context;
if($priority) $parameters['Priority'] = $priority;
if($application) $parameters['Application'] = $application;
if($data) $parameters['Data'] = $data;
if($timeout) $parameters['WaitTime'] = $timeout;
if($callerid) $parameters['CallerID'] = $callerid;
if($variable) $parameters['Variable'] = $variable;
if($account) $parameters['Account'] = $account;
if(!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false';
if($actionid) $parameters['ActionID'] = $actionid;
// print_r($parameters);
return $this->send_request('Originate', $parameters);
}
/**
* List parked calls
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls
* @param string $actionid message matching variable
*/
function ParkedCalls($actionid=NULL)
{
if($actionid)
return $this->send_request('ParkedCalls', array('ActionID'=>$actionid));
else
return $this->send_request('ParkedCalls');
}
/**
* Ping
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Ping
*/
function Ping()
{
return $this->send_request('Ping');
}
/**
* Queue Add
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueAdd
* @param string $queue
* @param string $interface
* @param integer $penalty
*/
function QueueAdd($queue, $interface, $penalty=0)
{
$parameters = array('Queue'=>$queue, 'Interface'=>$interface);
if($penalty) $parameters['Penalty'] = $penalty;
return $this->send_request('QueueAdd', $parameters);
}
/**
* Queue Remove
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueRemove
* @param string $queue
* @param string $interface
*/
function QueueRemove($queue, $interface)
{
return $this->send_request('QueueRemove', array('Queue'=>$queue, 'Interface'=>$interface));
}
/**
* Queues
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Queues
*/
function Queues()
{
return $this->send_request('Queues');
}
/**
* Queue Status
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+QueueStatus
* @param string $actionid message matching variable
*/
function QueueStatus($actionid=NULL)
{
if($actionid)
return $this->send_request('QueueStatus', array('ActionID'=>$actionid));
else
return $this->send_request('QueueStatus');
}
/**
* Redirect
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Redirect
* @param string $channel
* @param string $extrachannel
* @param string $exten
* @param string $context
* @param string $priority
*/
function Redirect($channel, $extrachannel, $exten, $context, $priority)
{
return $this->send_request('Redirect', array('Channel'=>$channel, 'ExtraChannel'=>$extrachannel, 'Exten'=>$exten,
'Context'=>$context, 'Priority'=>$priority));
}
/**
* Set the CDR UserField
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetCDRUserField
* @param string $userfield
* @param string $channel
* @param string $append
*/
function SetCDRUserField($userfield, $channel, $append=NULL)
{
$parameters = array('UserField'=>$userfield, 'Channel'=>$channel);
if($append) $parameters['Append'] = $append;
return $this->send_request('SetCDRUserField', $parameters);
}
/**
* Set Channel Variable
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar
* @param string $channel Channel to set variable for
* @param string $variable name
* @param string $value
*/
function SetVar($channel, $variable, $value)
{
return $this->send_request('SetVar', array('Channel'=>$channel, 'Variable'=>$variable, 'Value'=>$value));
}
/**
* Channel Status
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status
* @param string $channel
* @param string $actionid message matching variable
*/
function Status($channel, $actionid=NULL)
{
$parameters = array('Channel'=>$channel);
if($actionid) $parameters['ActionID'] = $actionid;
return $this->send_request('Status', $parameters);
}
/**
* Stop monitoring a channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+StopMonitor
* @param string $channel
*/
function StopMontor($channel)
{
return $this->send_request('StopMonitor', array('Channel'=>$channel));
}
/**
* Dial over Zap channel while offhook
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDialOffhook
* @param string $zapchannel
* @param string $number
*/
function ZapDialOffhook($zapchannel, $number)
{
return $this->send_request('ZapDialOffhook', array('ZapChannel'=>$zapchannel, 'Number'=>$number));
}
/**
* Toggle Zap channel Do Not Disturb status OFF
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDoff
* @param string $zapchannel
*/
function ZapDNDoff($zapchannel)
{
return $this->send_request('ZapDNDoff', array('ZapChannel'=>$zapchannel));
}
/**
* Toggle Zap channel Do Not Disturb status ON
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapDNDon
* @param string $zapchannel
*/
function ZapDNDon($zapchannel)
{
return $this->send_request('ZapDNDon', array('ZapChannel'=>$zapchannel));
}
/**
* Hangup Zap Channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapHangup
* @param string $zapchannel
*/
function ZapHangup($zapchannel)
{
return $this->send_request('ZapHangup', array('ZapChannel'=>$zapchannel));
}
/**
* Transfer Zap Channel
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapTransfer
* @param string $zapchannel
*/
function ZapTransfer($zapchannel)
{
return $this->send_request('ZapTransfer', array('ZapChannel'=>$zapchannel));
}
/**
* Zap Show Channels
*
* @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ZapShowChannels
* @param string $actionid message matching variable
*/
function ZapShowChannels($actionid=NULL)
{
if($actionid)
return $this->send_request('ZapShowChannels', array('ActionID'=>$actionid));
else
return $this->send_request('ZapShowChannels');
}
// *********************************************************************************************************
// ** MISC **
// *********************************************************************************************************
/*
* Log a message
*
* @param string $message
* @param integer $level from 1 to 4
*/
function log($message, $level=1)
{
if($this->pagi != false)
$this->pagi->conlog($message, $level);
else
error_log(date('r') . ' - ' . $message);
}
/**
* Add event handler
*
* Known Events include ( http://www.voip-info.org/wiki-asterisk+manager+events )
* Link - Fired when two voice channels are linked together and voice data exchange commences.
* Unlink - Fired when a link between two voice channels is discontinued, for example, just before call completion.
* Newexten -
* Hangup -
* Newchannel -
* Newstate -
* Reload - Fired when the "RELOAD" console command is executed.
* Shutdown -
* ExtensionStatus -
* Rename -
* Newcallerid -
* Alarm -
* AlarmClear -
* Agentcallbacklogoff -
* Agentcallbacklogin -
* Agentlogoff -
* MeetmeJoin -
* MessageWaiting -
* join -
* leave -
* AgentCalled -
* ParkedCall - Fired after ParkedCalls
* Cdr -
* ParkedCallsComplete -
* QueueParams -
* QueueMember -
* QueueStatusEnd -
* Status -
* StatusComplete -
* ZapShowChannels - Fired after ZapShowChannels
* ZapShowChannelsComplete -
*
* @param string $event type or * for default handler
* @param string $callback function
* @return boolean sucess
*/
function add_event_handler($event, $callback)
{
$event = strtolower($event);
if(isset($this->event_handlers[$event]))
{
$this->log("$event handler is already defined, not over-writing.");
return false;
}
$this->event_handlers[$event] = $callback;
return true;
}
/**
* Process event
*
* @access private
* @param array $parameters
* @return mixed result of event handler or false if no handler was found
*/
function process_event($parameters)
{
$ret = false;
$e = strtolower($parameters['Event']);
$this->log("Got event.. $e");
$handler = '';
if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e];
elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*'];
if(function_exists($handler))
{
$this->log("Execute handler $handler");
$ret = $handler($e, $parameters, $this->server, $this->port);
}
else
$this->log("No event handler for event '$e'");
return $ret;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -