脚本说明
主要功能如下:
- 呼叫指定并发数、总呼叫数和接收呼叫的服务器
- 收到挂断事件之后,自动发起新的呼叫,用于保证并发数始终不掉下来
- 用于接收呼叫的是两个sip服务器,一个接听一个拒绝接听
脚本代码
```lua local concurrent = argv[1] —并发数 local total = argv[2] —总的呼叫数 local callerNum = argv[2] or 17000000000 local calledNum = argv[3] or 1800000000; —起始的主机号码 local answerServerIpPort = argv[4] or “172.16.102.104:56660” —用于接受呼叫并放音的目标服务器地址 local rejectServerIpPort = argv[5] or “172.16.102.104:56661” —用于拒接呼叫的服务器地址
local remainCount = total
function log(content, level) level = level or “debug”; freeswitch.consoleLog(level, argv[0] .. “:” .. content .. “\n”); end
api = freeswitch.API() function makeCall() local srcNum = callerNum + (total - remainCount) local destNum = calledNum + (total - remainCount)
local serverIp = answerServerIpPort;
--如果被叫号码尾号是偶数, 则走到不接通的sipp上面去
local key = string.sub(destNum,-1)
if key =="2" or key == "4" or key == "6" or key=="8" or key=="0" then
serverIp = rejectServerIpPort;
end
local cmd= "bgapi originate {absolute_codec_string=PCMA}sofia/internal/" .. destNum .. "@" .. serverIp .. " &park";
log("start to make call, cmd:" .. cmd)
api:executeString(cmd)
end
function eventMonitor() con = freeswitch.EventConsumer(); con:bind(“CHANNEL_HANGUP”); con:bind(“custom”, “KILL_SCRIPT”); for e in (function() return con:pop(1) end) do event = e:getHeader(“Event-Subclass”);
if not event then
event = e:getHeader("Event-Name");
end
if event == "KILL_SCRIPT" then
local scriptName = e:getHeader("script_name");
if scriptName == argv[0] then
log("start to exit...");
return;
end
elseif event == "CHANNEL_HANGUP" then
if remainCount <= 0 then
log("all finished...exit...")
return
end
makeCall();
remainCount = remainCount - 1
end
end
end
— make init call do for i=0,concurrent-1 do remainCount = remainCount - 1 makeCall(); freeswitch.msleep(40) end
eventMonitor()
end
```