通过执行FreeSWITC的API命令,可以获取另一条信道的信息,如下:
show channels like 66903@ as xml
在该命令的返回值中抽取sent_callee_num,即为另一方的号码。
下面是具体的实现方法:
[plain] view plaincopy--根据一方号码获取另一条腿的UUID function getOtherLegUUID(api,num) local uuid local res=api:executeString("show channels like "..num.."@ as xml")----判断获取的channel信息是否为空 --fslog("debug","show channels res",res) --如果channel信息不为空 if res and string.len(res) >0 then local _,_, sendCalleeNum = string.find(res,"<sent_callee_num>(.-)<%/sent_callee_num>") if sendCalleeNum then uuid = getUUIDByNum(api,sendCalleeNum) end endreturn uuid end
2、如何向另一方号码发送dtmf?
解决方法:
该问题比较容易处理,只需要调用uuid_send_dtmf方法即可。前提条件是获取到那个信道的UUID。
具体代码
下面是完整的脚本代码,仅供参考:
[plain] view plaincopy--/****************************************************/ --脚本名称:send_dtmf_toleg.lua --脚本参数: -- argv[1] 当前通话的号码 -- argv[2] 待发送的dtmf信息 --脚本功能: -- 根据当前通话的号码,查出另一条腿的uuid,然后向该uuid发送dtmf --作者: 默言 2013-11-24 --/****************************************************/--输出freeeswitch日志 function fslog(loglevel,logtitle, logbody) loglevel = loglevel or "debug" logtitle = logtitle or "" logbody = logbody or "" freeswitch.consoleLog(loglevel, "\n" .. argv[0] .. " : " .. logtitle .. "{" .. logbody .. "}\n") end--获取号码对应的uuid --参数:num, 待查询号码 --返回:号码对应的通道的uuid function getUUIDByNum(api, num) local uuid local res=api:executeString("show channels like "..num.."@ as xml") if res then --使用正则表达式从字符串中截取uuid --'-'代表最短匹配 _,_,uuid = string.find(res,"<uuid>(.-)<%/uuid>") endfslog("debug","getUUID:" .. num, uuid) return uuid end--根据一方号码获取另一条腿的UUID function getOtherLegUUID(api,num) local uuid local res=api:executeString("show channels like "..num.."@ as xml")----判断获取的channel信息是否为空 --fslog("debug","show channels res",res) --如果channel信息不为空 if res and string.len(res) >0 then local _,_, sendCalleeNum = string.find(res,"<sent_callee_num>(.-)<%/sent_callee_num>") if sendCalleeNum then uuid = getUUIDByNum(api,sendCalleeNum) end endreturn uuid end do local legNum=argv[1] --待发送的dtmf信息 local dtmfs = argv[2] fslog("debug","start to send dtmf, legnum",legNum) fslog("debug","need send dtmfs", dtmfs) if legNum and tonumber(legNum) then api=freeswitch.API() uuid=getOtherLegUUID(api, legNum) if uuid then local cmd = "uuid_send_dtmf " .. uuid .. " " .. dtmfs fslog("debug","send_dtmf cmd", cmd) api:executeString(cmd) else fslog("warning","cannot get another leg uuid","") end else fslog("warning","invalid parameters","") end end
DTMF就是双音频脉冲拨号,一个高频,一个低频组合形成一个数字,构成了一个矩阵,也没有什么原理,这是统一的一种编码方式,约定好的,交换机和电话机以此来识别号码。百度管理员封了我的空间,本来以后不打算参与百度知道来,今天破例了