如何得到Asterisk中MYSQL里存放的所有用户的分机号

如何得到Asterisk中MYSQL里存放的所有用户的分机号

 

最近有这样的一个场景,在打电话的系统中需要得到Asterisk中MYSQL里存放的所有用户的分机号, 因为从其它途径得到的电话号码可能不准确. 具体使用场景是:当使用者找到自己要联系的员工后, 系统通过员工姓名到Asterisk服务器上找到相应的员工所对应的电话号码,并将当前电话与所找员工的电话进行联通.

 

1,打开Asterisk服务器上的/etc/asterisk/extensions_additional.conf配置文件.

less /etc/asterisk/extensions_additional.conf

它里面有下面这样的配置.

[globals]
VM_DDTYPE = b
VM_GAIN = 12
OPERATOR_XTN = 500
VMX_TIMEOUT = 2
VMX_REPEAT = 1
VMX_LOOPS = 1
VM_OPTS = 
VMX_OPTS_LOOP = 
VMX_OPTS_DOVM = 
CFDEVSTATE = TRUE
DNDDEVSTATE = TRUE
FMDEVSTATE = TRUE
QUEDEVSTATE = TRUE
QUEUETOGGLE = *45
QUEUEPAUSETOGGLE = *46
DYNAMIC_FEATURES = apprecord
INTERCOMCODE = nointercom
ASTETCDIR = /etc/asterisk
ASTMODDIR = /usr/lib/asterisk/modules
ASTVARLIBDIR = /var/lib/asterisk
ASTAGIDIR = /var/lib/asterisk/agi-bin
ASTSPOOLDIR = /var/spool/asterisk
ASTRUNDIR = /var/run/asterisk
ASTLOGDIR = /var/log/asterisk
CWINUSEBUSY = true
AMPMGRUSER = admin
AMPMGRPASS = amp111
AMPDBENGINE = mysql
AMPDBHOST = localhost
AMPDBNAME = asterisk
AMPDBUSER = freepbxuser
AMPDBPASS = mUR24T1Jntfi
VMX_CONTEXT = from-internal
VMX_PRI = 1
VMX_TIMEDEST_CONTEXT = 
VMX_TIMEDEST_EXT = dovm
VMX_TIMEDEST_PRI = 1
VMX_LOOPDEST_CONTEXT = 
VMX_LOOPDEST_EXT = dovm
VMX_LOOPDEST_PRI = 1
MIXMON_DIR = 
MIXMON_POST = 
DIAL_OPTIONS = Ttr
TRUNK_OPTIONS = Tt
......

其中如下则为MYSQL的配置信息.

AMPDBENGINE = mysql
AMPDBHOST = localhost
AMPDBNAME = asterisk
AMPDBUSER = freepbxuser
AMPDBPASS = mUR24T1Jntfi

2,通过上面的配置信息,使用MYSQL客户端去连接. 如果出现错误:错误码:1130 Host 'xxx' is not allowed to connect to this MySQL server, 请参考另一文章:http://jerval.iteye.com/admin/blogs/2101747 去解决.

3,连接成功后,会看到如下两个有关的数据库.

asterisk
asteriskcdrdb

 其中asterisk是Asterisk的核心配置信息.而asteriskcdrdb则是用于记录通话记录的. 这里我们打开asterisk数据库,找到devices表,打开表就能看到所有用户的分机号了. 表结构如下:

Field	Type	Null	Key	Default	Extra
id	varchar(20)	NO			
tech	varchar(10)	NO			
dial	varchar(50)	NO			
devicetype	varchar(5)	NO			
user	varchar(50)	YES		NULL	
description	varchar(50)	YES		NULL	
emergency_cid	varchar(100)	YES		NULL	

 到此就可以通过JDBC或者其它数据访问代码来对这些信息进行访问了.

 

 

 

你可能感兴趣的:(mysql)