Files
resty_functions/scripts/lib/upt.lua
T
2023-05-07 02:24:32 +08:00

29 lines
1.0 KiB
Lua

-- 指定模块引用目录,否则无法加载同目录下的其他文件
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local _M = {}
function _M.upt(uri)
local hostname = ngx.var.host
ngx.log(ngx.INFO, 'hostname...', hostname)
local secret;
if string.find(hostname, "moicen.com") then
secret = ngx.var.upt_moicen_secret
elseif string.find(hostname, "alchemy-studio.cn") then
secret = ngx.var.upt_alchemy_secret
elseif string.find(hostname, "huiwings.cn") then
secret = ngx.var.upt_huiwings_secret
end
ngx.log(ngx.INFO, 'secret...' .. secret)
local duration = ngx.var.upt_duration
local etime = os.time() + duration
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. uri)
ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime)
local upt = string.sub(sign, 13, 13 + 7) .. etime
ngx.log(ngx.INFO, 'upt...' .. upt)
return (upt)
end
return _M