#!/usr/local/bin/lua
package.path = "/usr/local/share/lua/5.1/?.lua"
package.cpath = "/usr/local/lib/lua/5.1/?.so"
local http = require("socket.http")
local ltn12 = require("ltn12")
function http.get(u)
local t= {}
local r,c,h=http.request{
url = u,
sink = ltn12.sink.table(t)}
return r,c,h,table.concat(t)
end
--发送http.get 请求,返回响应结果
function wb_getUrl(url)
r,c,h,body = http.get(url)
if c ~= 200 then
print ("ErrorCode:" .. c)
return
else
return body
end
end
--写入日志
function writeFile(fname,data)
f = io.open(fname,"wb")
if f then
f:write(data)
f:close()
return true
else
return false
end
end
--定义接口地址及业务队列名称
url = "http://.x.x.x:6898/"
body = wb_getUrl(url)
session:execute("log","INFO BODY CONTEXT SK_ZRG:"..body.."\n")
--writeFile("test.txt",body)
--根据接口返回结果判断走不同的流程;1 人工工作时间;0非人工工作时间。
if ( body == "1" ) then
session:execute("transfer","25001 XML default")
else
session:execute("playback","/usr/local/freeswitch/sounds/cx.wav")
end
-------------------
<param name="odbc-dsn" value="pgsql://host=10.x.x.x dbname=freeswitch user=postgres password='cx' options='-c client_min_messages=NOTICE' application_name='freeswitch'"/>
https://w3.impa.br/~diego/software/luasocket/http.html#request
转载请注明:SuperIT » lua-http访问接口