MySQL,Asterisk拨号计划和呼叫转移

如何通过将来电号码与要转接的号码相匹配来使Asterisk转发来电?这两个数字都存储在MySQL数据库中.

解决方法:

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

我假设您的服务器已经具有带有PDO库的现代版本的PHP(位于/usr/bin/php),并且您具有名为fwd_table的数据库表,其中包含列caller_id和destination.

在/ 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正确.如果您需要更多帮助以将其集成到拨号计划中,请编辑您的问题.

上一篇:<题解> CF1276F Asterisk Substrings


下一篇:@codeforces - 1276F@ Asterisk Substrings