【问题标题】:MySQL, Asterisk Dialplans and call forwardingMySQL、Asterisk Dialplans 和呼叫转移
【发布时间】:2008-09-16 05:53:02
【问题描述】:

如何让 Asterisk 根据来电号码与要转发的号码匹配来转发来电?这两个数字都存储在 MySQL 数据库中。

【问题讨论】:

    标签: mysql asterisk telephony


    【解决方案1】:

    抱歉,代码示例太长,但其中一半以上是调试代码以帮助您进行设置。

    我假设您的服务器已经有了带有 PDO 库的现代版本的 PHP(/usr/bin/php),并且您有一个名为 fwd_table 的数据库表,其中包含 caller_iddestination 列。

    在 /var/lib/asterisk/agi-bin 中获取PHP AGI 库的副本。然后创建一个名为 forward_by_callerid.agi 的文件,其中包含:

    #!/usr/bin/php
    <?php
    ini_set('display_errors','false'); //Supress errors getting sent to the Asterisk process
    
    require('phpagi.php');
    $agi = new AGI();
    
    try {
        $pdo = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=UTF-8', $db_user, $db_pass);
    } catch (PDOException $e) {
        $agi->conlog("FAIL: Error connecting to the database! " . $e->getMessage());
        die();
    }
    
    $find_fwd_by_callerid = $pdo->prepare('SELECT destination FROM fwd_table WHERE caller_id=? ');
    
    $caller_id = $agi->request['agi_callerid'];
    
    if($callerid=="unknown" or $callerid=="private" or $callerid==""){
        $agi->conlog("Call came in without caller id, I give up");
        exit;
    }else{
        $agi->conlog("Call came in with caller id number $caller_id.");
    }
    
    if($find_fwd_by_callerid->execute(array($caller_id)) === false){
        $agi->conlog("Database problem searching for forward destination (find_fwd_by_callerid), croaking");
        exit;
    } 
    $found_fwds = $find_fwd_by_callerid->fetchAll();
    if(count($found_fwds) > 0){
        $destination = $found_contacts[0]['destination'];
        $agi->set_variable('FWD_TO', $destination);
    
        $agi->conlog("Caller ID matched, setting FWD_TO variable to ''");
    }
    
    ?>
    

    然后从拨号计划中你可以这样称呼它:

    AGI(forward_by_callerid.agi)
    

    如果你的数据库有匹配,它会设置变量FWD_TO。如果您需要更多帮助以将其集成到您的拨号计划中,请编辑您的问题。

    【讨论】:

      【解决方案2】:

      This article 应该可以解决问题。大约 3 行代码和一些简单的查询来添加和删除转发规则。

      【讨论】:

      • 非常接近。没有涵盖问题的 MySQL 部分,但我认为它让我走得足够远。只是需要一些例子。谢谢!
      【解决方案3】:

      我一直在寻找的解决方案最终看起来像这样:

      [default]
      exten => _X.,1,Set(ARRAY(${EXTEN}_phone)=${DTC_ICF(phone_number,${EXTEN})})
      exten => _X.,n(callphone),Dial(SIP/metaswitch/${${EXTEN}_phone},26)
      exten => _X.,n(end),Hangup()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多