使用Asterisk manager API實現自動撥號

來源:互聯網
上載者:User

 在實現自動呼叫的樣本中我使用的是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

各位看官可以自己擴充一下,比如通過訪問網址來傳遞呼叫參數!或者通過某些程式自動執行該程式!我只想把這個用到伺服器監控上面,不用再使用舊的簡訊通知,如果宕機就直接撥負責人的電話,接通之後自動撥放錄音,還要迴圈播放,讓他不知道都難!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.