脚本说明

主要功能如下:

  1. 呼叫指定并发数、总呼叫数和接收呼叫的服务器
  2. 收到挂断事件之后,自动发起新的呼叫,用于保证并发数始终不掉下来
  3. 用于接收呼叫的是两个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)

  1. local serverIp = answerServerIpPort;
  2. --如果被叫号码尾号是偶数, 则走到不接通的sipp上面去
  3. local key = string.sub(destNum,-1)
  4. if key =="2" or key == "4" or key == "6" or key=="8" or key=="0" then
  5. serverIp = rejectServerIpPort;
  6. end
  7. local cmd= "bgapi originate {absolute_codec_string=PCMA}sofia/internal/" .. destNum .. "@" .. serverIp .. " &park";
  8. log("start to make call, cmd:" .. cmd)
  9. 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”);

  1. if not event then
  2. event = e:getHeader("Event-Name");
  3. end
  4. if event == "KILL_SCRIPT" then
  5. local scriptName = e:getHeader("script_name");
  6. if scriptName == argv[0] then
  7. log("start to exit...");
  8. return;
  9. end
  10. elseif event == "CHANNEL_HANGUP" then
  11. if remainCount <= 0 then
  12. log("all finished...exit...")
  13. return
  14. end
  15. makeCall();
  16. remainCount = remainCount - 1
  17. end
  18. end

end

— make init call do for i=0,concurrent-1 do remainCount = remainCount - 1 makeCall(); freeswitch.msleep(40) end

  1. eventMonitor()

end

```