php-asmanager.php
来自「最近在做软交换时研究的一个软交换的东东」· PHP 代码 · 共 783 行 · 第 1/2 页
PHP
783 行
function ListCommands() { return $this->send_request('ListCommands'); } /** * Logoff Manager * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Logoff */ function Logoff() { return $this->send_request('Logoff'); } /** * Check Mailbox Message Count * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxCount * @param string $mailbox */ function MailboxCount($mailbox) { return $this->send_request('MailboxCount', array('Mailbox'=>$mailbox)); } /** * Check Mailbox * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+MailboxStatus * @param string $mailbox */ function MailboxStatus($mailbox) { return $this->send_request('MailboxStatus', array('Mailbox'=>$mailbox)); } /** * Monitor a channel * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Monitor * @param string $channel * @param string $file */ function Monitor($channel, $file) { return $this->send_request('Monitor', array('Channel'=>$channel, 'File'=>$file)); } /** * Originate Call * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Originate * @param string $channel * @param string $exten * @param string $context * @param string $priority * @param integer $timeout * @param string $callerid * @param string $variable * @param string $account * @param string $application * @param string $data */ function Originate($channel, $exten, $context, $priority, $timeout, $callerid, $variable, $account, $application, $data) { $parameters = array(); if($channel) $parameters['Channel'] = $channel; if($exten) $parameters['Exten'] = $exten; if($context) $parameters['Context'] = $context; if($priority) $parameters['Priority'] = $priority; if($timeout) $parameters['Timeout'] = $timeout; if($callerid) $parameters['CallerID'] = $callerid; if($variable) $parameters['Variable'] = $variable; if($account) $parameters['Account'] = $account; if($application) $parameters['Application'] = $application; if($data) $parameters['Data'] = $data; return $this->send_request('Originate', $parameters); } /** * List parked calls * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+ParkedCalls */ function ParkedCalls() { 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'); } /** * 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 */ function QueueStatus() { 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 */ function SetCDRUserField() { // XXX need to look at source to find this function... return $this->send_request('SetCDRUserField'); } /** * Set Channel Variable * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+SetVar * @param string $channel * @param string $variable * @param string $value */ function SetVar($channel, $variable, $value) { return $this->send_request('SetVar', array('Channel'=>$channel, 'Variable'=>$variable, 'Value'=>$value)); } /** * List SIP Peers */ function SIPpeers() { // XXX need to look at source to find this function... return $this->send_request('SIPpeers'); } /** * Channel Status * * @link http://www.voip-info.org/wiki-Asterisk+Manager+API+Action+Status * @param string $channel */ function Status($channel) { return $this->send_request('Status', array('Channel'=>$channel)); } /** * 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 */ function ZapDialOffhook() { // XXX need to look at source to find this function... return $this->send_request('ZapDialOffhook'); } /** * Toggle Zap channel Do Not Disturb status OFF */ function ZapDNDoff() { // XXX need to look at source to find this function... return $this->send_request('ZapDNDoff'); } /** * Toggle Zap channel Do Not Disturb status ON */ function ZapDNDon() { // XXX need to look at source to find this function... return $this->send_request('ZapDNDon'); } /** * Hangup Zap Channel */ function ZapHangup() { // XXX need to look at source to find this function... return $this->send_request('ZapHangup'); } /** * Transfer Zap Channel */ function ZapTransfer() { // XXX need to look at source to find this function... return $this->send_request('ZapTransfer'); } /* * 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 - * Cdr - * ParkedCallsComplete - * QueueParams - * QueueMember - * QueueStatusEnd - * Status - * StatusComplete - * 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; } /** Show all entries in the asterisk database * @return Array associative array of key=>value */ function database_show() { $r = $this->command("database show"); $data = explode("\n",$r["data"]); $db = array(); foreach ($data as $line) { $temp = explode(":",$line); $db[ trim($temp[0]) ] = trim($temp[1]); } return $db; } /** Add an entry to the asterisk database * @param string $family The family name to use * @param string $key The key name to use * @param mixed $value The value to add * @return bool True if successful */ function database_put($family, $key, $value) { $r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value); return (bool)strstr($r["data"], "success"); } /** Get an entry from the asterisk database * @param string $family The family name to use * @param string $key The key name to use * @return mixed Value of the key, or false if error */ function database_get($family, $key) { $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); $data = strpos($r["data"],"Value:"); if ($data !== false) { return trim(substr($r["data"],6+$data)); } else { return false; } } /** Delete an entry from the asterisk database * @param string $family The family name to use * @param string $key The key name to use * @return bool True if successful */ function database_del($family, $key) { $r = $this->command("database del ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); return (bool)strstr($r["data"], "removed"); } /** Delete a family from the asterisk database * @param string $family The family name to use * @return bool True if successful */ function database_deltree($family) { $r = $this->command("database deltree ".str_replace(" ","/",$family)); return (bool)strstr($r["data"], "removed"); } }?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?