asterisk使用mysql_MySQL,Asterisk拨号计划和呼叫转移

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

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

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值