freeswitch用户整合(使用mysql数据库的用户表)

本文介绍如何通过配置unixodbc、使用Lua脚本验证用户及调整拨号计划,实现FreeSWITCH系统的用户整合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

freeswitch是一款强大的voip服务器,可以语音和视频。但是它默认是采用/directory文件夹下的xml来配置用户的,对于整合到现有系统或者使用数据库保存用户信息的系统都是非常不方便的,所以,本文主要描述一种方法,解决freeswitch用户整合的问题。


完成这一任务需要三步,配置unixodbc,将用户验证转接到lua脚本,修改拨号计划使得拨通所有号码

 


 

 

开发环境:centos 6.2 64位,  freeswitch,  linphone,mysql


1  首先安装unixodbc

    unixODBC是一个可以让你在Unix/Linux系统下使用ODBC来连接数据库的组件,就像java中的mysql-connector-java-5.1.6-bin.jar一样,负责连接数据库的。


yum install unixODBC-devel.x86_64

yum install mysql-connector-odbc.x86_64


安装后修改两个文件:/etc/odbc.ini,/etc/odbcinst.ini


/etc/odbc.ini  配置要连接的数据库信息


[freeswitch]

Driver          = /usr/lib64/libmyodbc5.so

SERVER       = ip

PORT           = 3306

DATABASE    = database

USER            = user

PASSWORD   = password


/etc/odbcinst.ini 修改mysq的部分,将驱动包指向正确,这要根据你本身的包安装路径配置


# Example driver definitions


# Driver from the postgresql-odbc package

# Setup from the unixODBC package

[PostgreSQL]

Description     = ODBC for PostgreSQL

Driver          = /usr/lib/psqlodbc.so

Setup           = /usr/lib/libodbcpsqlS.so

Driver64        = /usr/lib64/psqlodbc.so

Setup64         = /usr/lib64/libodbcpsqlS.so

FileUsage       = 1



# Driver from the mysql-connector-odbc package

# Setup from the unixODBC package

[MySQL]

Description     = ODBC for MySQL

Driver          = /usr/lib64/libmyodbc5.so

Setup           = /usr/lib64/libodbcmyS.so

Driver64        = /usr/lib64/libmyodbc5.so

Setup64         = /usr/lib64/libodbcmyS.so

FileUsage       = 1



修改之后,执行  isql -v freeswitch
如果出现
[root@test etc]# isql -v freeswitch
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> 
则代表你的unixodbc配置成功了

2  修改用户注册部分,转接到lua脚本进行注册验证

修改freeswitch/conf/autoload_configs/lua.conf.xml


<configuration name="lua.conf" description="LUA Configuration">

  <settings>


    <!--

    Specify local directories that will be searched for LUA modules

    These entries will be pre-pended to the LUA_CPATH environment variable

    -->

    <!-- <param name="module-directory" value="/usr/lib/lua/5.1/?.so"/> -->

    <!-- <param name="module-directory" value="/usr/local/lib/lua/5.1/?.so"/> -->


    <!--

    Specify local directories that will be searched for LUA scripts

    These entries will be pre-pended to the LUA_PATH environment variable

    -->

    <!-- <param name="script-directory" value="/usr/local/lua/?.lua"/> -->

    <!-- <param name="script-directory" value="$${base_dir}/scripts/?.lua"/> -->


    <!--<param name="xml-handler-script" value="/dp.lua"/>-->

    <!--<param name="xml-handler-bindings" value="dialplan"/>-->

    <param name="xml-handler-script" value="gen_dir_user_xml.lua" />

    <param name="xml-handler-bindings" value="directory" />

    <!--

        The following options identifies a lua script that is launched

        at startup and may live forever in the background.

        You can define multiple lines, one for each script you

        need to run.

    -->

    <!--<param name="startup-script" value="startup_script_1.lua"/>-->

    <!--<param name="startup-script" value="startup_script_2.lua"/>-->

  </settings>

</configuration>

让lua脚本接管用户注册验证,这里默认调用的脚本是freeswitch/script/gen_dir_user_xml.lua
脚本内容如下:
freeswitch.consoleLog("NOTICE","lua take the users...\n");
-- gen_dir_user_xml.lua
-- example script for generating user directory XML

-- comment the following line for production:
--freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, provided params:\n" .. params:serialize() .. "\n")

local req_domain = params:getHeader("domain")
local req_key    = params:getHeader("key")
local req_user   = params:getHeader("user")
local req_password   = params:getHeader("pass")

local dbh = freeswitch.Dbh("freeswitch","user","password");
freeswitch.consoleLog("NOTICE","start connect DB...\r\n");
assert(dbh:connected());
dbh:query("select password from Users where id="..req_user,function(row)
        freeswitch.consoleLog("NOTICE",string.format("%s\n",row.password))
        req_password=string.format("%s",row.password)
end);
dbh:release();

freeswitch.consoleLog("NOTICE","info:"..req_domain.."--"..req_key.."--"..req_user.."--"..req_password.."\n");



--assert (req_domain and req_key and req_user,
--"This example script only supports generating directory xml for a single user !\n")
if req_domain ~= nil and req_key~=nil and req_user~=nil then
    XML_STRING =
    [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="freeswitch/xml">
      <section name="directory">
        <domain name="]]..req_domain..[[">
          <params>
        <param name="dial-string"
        value="{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"/>
          </params>
          <groups>
        <group name="default">
          <users>
            <user id="]] ..req_user..[[">
              <params>
            <param name="password" value="]]..req_password..[["/>
            <param name="vm-password" value="]]..req_password..[["/>
              </params>
              <variables>
            <variable name="toll_allow" value="domestic,international,local"/>
            <variable name="accountcode" value="]] ..req_user..[["/>
            <variable name="user_context" value="default"/>
            <variable name="directory-visible" value="true"/>
            <variable name="directory-exten-visible" value="true"/>
            <variable name="limit_max" value="15"/>
            <variable name="effective_caller_id_name" value="Extension ]] ..req_user..[["/>
            <variable name="effective_caller_id_number" value="]] ..req_user..[["/>
            <variable name="outbound_caller_id_name" value="${outbound_caller_name}"/>
            <variable name="outbound_caller_id_number" value="${outbound_caller_id}"/>
            <variable name="callgroup" value="techsupport"/>
              </variables>
            </user>
          </users>
        </group>
          </groups>
        </domain>
      </section>
    </document>]]
else
    XML_STRING =
    [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document type="freeswitch/xml">
      <section name="directory">
      </section>
    </document>]]
end

-- comment the following line for production:
freeswitch.consoleLog("notice", "Debug from gen_dir_user_xml.lua, generated XML:\n" .. XML_STRING .. "\n");


修改freeswitch/conf/directory中的一部分内容,使得通过xml验证用户的功能失效,这样lua才能真正接管用户注册
删除的内容如下:
<group name="default">
        <users>
          <X-PRE-PROCESS cmd="include" data="default/*.xml"/>
        </users>
 </group>


3  修改拨号计划
修改freeswitch/conf/dialplan/default.xml
修改如下内容,好让所有的拨号通过以下的条件
 <extension name="Local_Extension">
       <!--<condition field="destination_number" expression="^(10[01][0-9])$">-->
       <condition field="destination_number" expression="^(.*)$">

完成以上步骤,就基本完成了用户整合的全部内容,但是要注意一点,第一步配置unixodbc之后,要重新编译下freeswitch的源码,即在/usr/local/src/freeswitch下执行 configure&&make install,然后重启freeswitch。
还有就是每次修改xml后都需要重新在freeswitch控制台或者fs_cli下执行reloadxml,使得修改生效,修改lua脚本,则不需要如上操作。

<think>好的,用户想了解IVR系统在电话通信中的实现和工作原理。首先我需要回忆一下IVR的基本概念。IVR全称是交互式语音应答,它允许用户通过电话按键或语音与系统互动。我之前在FreeSWITCH的资料里看到过相关介绍,可以引用那个。 接下来,要解释IVR的工作原理。可能需要分步骤说明,比如电话接入、语音提示、用户输入处理、逻辑执行等环节。还要提到关键技术,比如语音合成、语音识别、路由控制。这里要注意用户提到的是电话通信中的实现,所以可能需要涉及电话系统的组件,比如语音网关、PBX等。 然后,实现方式部分需要具体说明使用的技术或软件,比如FreeSWITCH如何配置IVR。可能需要提到XML配置文件、VXML或者脚本语言的使用。同时,结合用户提供的引用内容,引用[1]提到FreeSWITCH支持IVR,而引用[2]涉及IPCC的构成,比如IPIVR组件,这部分可以联系起来,说明IVR在呼叫中心中的位置和作用。 还要注意用户可能对技术细节感兴趣,比如如何将用户的按键输入转化为指令,或者如何处理语音识别结果。这时候需要区分DTMF和ASR的不同处理方式。 最后,生成相关问题的时候,要围绕IVR的扩展知识,比如优化方法、技术挑战、与其他系统的集成等。确保问题能引导用户深入理解。 需要检查是否遵循了系统级指令,比如数学公式的正确格式,但这里可能用不上。回答结构要清晰,分点说明,并且自然地插入引用标识。避免使用Markdown格式,保持口语化但专业。</think>### IVR系统在电话通信中的实现与工作原理 #### 一、IVR系统的基本原理 IVR(Interactive Voice Response)系统通过**语音导航**和**用户输入**实现自动化交互。其核心流程如下: 1. **电话接入**:用户拨号后,电话交换机(如FreeSWITCH)将呼叫路由至IVR模块[^1] 2. **语音提示**:系统播放预录或实时合成的语音菜单(例如:"按1查询余额,按2办理业务") 3. **输入采集**:通过两种方式接收用户指令: - DTMF(双音多频)信号:识别电话按键(如*#键) - ASR(自动语音识别):解析自然语音指令 4. **逻辑执行**:根据输入触发对应操作,例如: $$ \text{用户按1} \rightarrow \text{数据库查询} \rightarrow \text{语音播报结果} $$ #### 二、关键技术实现 1. **语音网关处理** - 将PSTN信号转换为VOIP数据包 - 支持G.711、G.729等编解码协议 2. **业务逻辑引擎** ```xml <!-- FreeSWITCH IVR配置示例 --> <menu name="main_menu" greet="welcome.wav" input="dtmf" timeout="5000"> <entry action="menu-exec-app" digits="1" param="balance_query"/> <entry action="menu-exec-app" digits="2" param="bill_payment"/> </menu> ``` 3. **集成接口** - 通过HTTP API/SOAP协议对接业务系统 - 支持数据库实时查询(如MySQL/Oracle) #### 三、典型系统架构 ```plaintext [PSTN网络] │ ▼ [语音网关/路由器] ←→ [IP-PBX] │ │ ▼ ▼ [DTMF解码器] [语音识别引擎] │ │ └─────[IVR核心]────┘ │ ▼ [业务系统/数据库集群] ``` (基于IPCC架构的现代IVR系统实现[^2]) #### 四、进阶功能实现 1. **智能路由**:根据用户历史数据动态调整菜单 2. **容错机制**:超时自动转人工坐席 3. **多通道整合**:与短信/网页同步显示菜单内容
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linyu19872008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值