原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://strugglelinux.blog.51cto.com/1009905/609161
最近在做公司的呼叫中心,一時心血來潮想實現自動呼叫功能,現在只做了個示例,用到的時候再擴展。
在實現自動呼叫的示例中我使用的是Asterisk manager API中的Originate方法,該方法在phpagi的中。具體定義如下:(英文我就不解釋了,我英文很水)
- /**
- * 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['Timeout'] = $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;
- return $this->send_request('Originate', $parameters);
- }
下面是服務端的簡單代碼(很簡單我只是實現執行該文件自動撥號,對方接聽後會聽到 hello world 的語音)
ami.php
- #!/usr/bin/php -q
- <?php
- include "phpagi-asmanager.php";
- $ams = new AGI_AsteriskManager();
- $ams->AGI_AsteriskManager("ami.conf");
- $result = $ams->connect();
- $res = $ams->Originate('sip/8001','8001','from-internal','1','Playback','hello-world',30000,'192.168.1.112');
- var_dump($res); //這個是查看輸出信息的調試代碼
- ?>
ami.conf文件是訪問API的驗證文件:內容如下:
- [asmanager]
- server=127.0.0.1 ; server to connect to
- port=5038 ; default manager port
- username=admin ; username for login
- secret=123456 ; password for login
該文件的內容要和asterisk內的/etc/asterisk/manager.conf 文件中的用戶密碼相同 ,以上兩個文件我是放在 /var/spool/asterisk/outgoing/ 目錄中的
(要給執行的權限)
以上編寫完成之後在服務器上直接運行就可以呼叫撥號了:
執行./ami.php
各位看官可以自己擴展一下,比如通過訪問網址來傳遞呼叫參數!或者通過某些程序自動執行該程序!我只想把這個用到服務器監控上面,不用再使用舊的短信提示,如果宕機就直接撥負責人的電話,接通之後自動撥放錄音,還要循環播放,讓他不知道都難!
本文出自 “我菜故我在” 博客,請務必保留此出處http://strugglelinux.blog.51cto.com/1009905/609161