Asterisk下 AGI查询mysql的程序脚本编写(笔记)

相关链接:

Asterisk AGI程序编写指南:http://bbs.voip88.com/thread-1684-1-1.html

asterisk agi应用编程入门: http://bbs.voip88.com/thread-39-1-1.html

Asterisk AGIhttp://www.voip-info.org/wiki/view/Asterisk+AGI

Asterisk perl agi: http://www.voip-info.org/index.php?content_id=3468

Asterisk AGI php:http://www.voip-info.org/wiki/view/Asterisk+AGI+php

phpagi:http://phpagi.sourceforge.net/

Asterisk simple php lookup mysql database to set callerid name:http://www.voip-info.org/wiki/view/Asterisk+simple+php+lookup+mysql+database+to+set+callerid+name

在mysql中添加数据库test,并在其中建立calleridlookup表:

create table calleridlookup(id smallint(6) NOT NULL auto_increment PRIMARY KEY, callernum varchar(20), destexten varchar(20));

插入几行数据

/var/lib/asteriks/agi-bin新建lookup.php脚本:
#!/usr/bin/php -q
<?
require 'phpagi.php';
$agi = new AGI();

$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);//remove any non numeric characters

/*
connect to "asterisk" database in mysql; in this case only 1 table "clients"
column telsearch contains concatenated mobile, home and work numbers
e.g. 0121777887207986238123
script will search for caller number within this field
*/
$db = 'test';
$dbuser = 'asteriskuser';
$dbpass = 'amp109';
$dbhost = 'localhost';

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$db") or die("could not open database");
//$row=mysql_query("select title,firstname,lastname from clients where telsearch like '%$no%' LIMIT 1");
$row=mysql_query("select destexten from calleridlookup where callernum like '8999' LIMIT 1");
if (mysql_num_rows($row)==1){//if found number and number greater than 4 digits to avoid 3 digit internal extensions
$row=mysql_fetch_array($row);
if ($row[destexten]) $name = $row[destexten];
// if ($row[title]) $name .= $row[title]." ";
// if ($row[firstname]) $name .= $row[firstname]." ";
// if ($row[lastname]) $name .= $row[lastname];
}
//else $name=$agi->request[agi_callerid];//else set calleridname to callerid number
else $name="0";

$agi->set_variable("destexten", $name);
?>

修改脚本权限:chmod 557 lookup.php

在dialplan中添加调用代码:

;添加根据来电号码查询数据库选择分机
exten => s,n,AGI(lookup.php)
exten => s,n,Noop(${destexten})
exten => s,n,GotoIf($["${destexten}" == "0"]?done) ; leave loop if no row found
exten => s,n,Noop(lookup sucess goto)
exten => s,n,Goto(from-did-direct,${destexten},1)
exten => s,n(done),Noop(lookup fail goto normal)

Powered by Zoundry Raven

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值