文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>asterisk下 agi查询mysql的程序脚本编写(笔记)...

asterisk下 agi查询mysql的程序脚本编写(笔记)...

时间:2010-08-17  来源:seven407

相关链接:

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

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

Asterisk AGI:http://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

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载