Files
resty_functions/test_scripts/test_upt.lua
T
2022-08-24 00:26:46 +08:00

37 lines
1.1 KiB
Lua

-- retrieve the content of a URL
local http = require "resty.http"
local pl = require "pl.pretty"
--local Upt = require "lib/upt"
local httpc = http:new()
local uri = "/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg"
local secret = "0D32E581A445404FA4C306709724FA07"
local duration = "3600"
local etime = os.time() + duration
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. uri)
--ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime)
ngx.say('sign...' .. sign .. ' etime..' .. etime)
local _upt = string.sub(sign, 13, 13 + 7) .. etime
--local _upt = Upt.upt()
ngx.say("UPT -> ", _upt)
local remote_url = "https://upyun.alchemy-studio.cn/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg?_upt=" .. _upt
local no_exception, resp, resp_err = pcall(httpc.request_uri, httpc, remote_url,
{
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
method = "GET",
})
ngx.say("RESP -> ", pl.write(resp))
---- save the content to a file
local f = assert(io.open('test.jpg', 'wb')) -- open in "binary" mode
f:write(resp.body)
--
f:close()