FreeSWITCH给指定地址发送SIP Message

SIP Message发到注册用户是很容易的,但是要发到指定的地址还是有点难度的。我查了半天mod_sofia的源码终于解决了。不多说了,直接上lua版本的示例代码:

function debug(s)
    freeswitch.consoleLog("ERR", s .. "\n")
end

local domain = "xxx.com.cn"
-- domain = freeswitch.expand("$${domain}") -- 这样似乎更好
local from = "1001"
local to = "1002"
local x_head = "1003" -- 扩展头
local body = "hello fs\r\n"
local sip_ip = "192.168.1.100"
local sip_port = "5060"
local event = freeswitch.Event("CUSTOM", "SMS::SEND_MESSAGE")

event:addHeader("proto", "sip")
event:addHeader("dest_proto", "sip")
event:addHeader("from",  from .. "@" .. domain)
event:addHeader("from_full", "sip:" .. from .. "@" .. domain)
event:addHeader("sip_h_X-head", x_head)
event:addHeader("to",  to .."@" .. domain)
event:addHeader("sip_profile", "internal") -- 改成自己的sip_profile
event:addHeader("profile", "internal")
event:addHeader("type", "text/plain")
event:addHeader("to_sip_ip", sip_ip)
event:addHeader("to_sip_port", sip_port)
event:addBody(body)
debug(event:serialize())
event:fire()

默认用udp发送,如果想用tcp发送,修改sip profile这个参数即可:

另外,记得加载mod_sms。

你可能感兴趣的:(FreeSWITCH,信息与通信)