使用Asterisk manager API实现自动拨号
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。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
转载于:https://blog.51cto.com/532074/1114470