From bbe33e2c314a4c7d1ec7a4c6379833a3a6ab1bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=94=B7?= Date: Wed, 24 Aug 2022 00:26:46 +0800 Subject: [PATCH] update test_upt --- test_scripts/test_upt.lua | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/test_scripts/test_upt.lua b/test_scripts/test_upt.lua index 6d8a775..2563655 100644 --- a/test_scripts/test_upt.lua +++ b/test_scripts/test_upt.lua @@ -1,10 +1,36 @@ -- retrieve the content of a URL -local http = require("socket.http") -local body, code = http.request("https://upyun.alchemy-studio.cn/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg?_upt=e487088a1661273055") -if not body then error(code) end +local http = require "resty.http" +local pl = require "pl.pretty" +--local Upt = require "lib/upt" +local httpc = http:new() --- save the content to a file +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(body) - +f:write(resp.body) +-- f:close()