android dtmf发送命令,如何向通话中的另一方发送DTMF

解决方法:

通过执行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,"(.-)"); if sendCalleeNum then uuid = getUUIDByNum(api,sendCalleeNum); end end return 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,"(.-)") end fslog("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,"(.-)"); if sendCalleeNum then uuid = getUUIDByNum(api,sendCalleeNum); end end return 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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值