如何让星号根据来电号码与要前转到的号码进行匹配来前转来电?这两个号码都存储在MySQL数据库中。
发布于 2009-12-09 03:20:48
我正在寻找的解决方案最终看起来像这样:
[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()发布于 2008-09-16 18:32:01
对于冗长的代码示例,很抱歉,但其中一半以上是调试代码,以帮助您进行设置。
我假设您的服务器已经有了带有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设置为your。如果您需要将此问题集成到拨号方案中的更多帮助,请编辑您的问题。
发布于 2008-09-16 05:58:51
This article应该可以做到这一点。这大约需要3行代码和一些简单的查询来添加和删除转发规则。
https://stackoverflow.com/questions/69676
复制相似问题