rename vars
This commit is contained in:
+15
-15
@@ -23,7 +23,7 @@ local function get_access_token()
|
||||
|
||||
ngx.log(ngx.INFO, "START REQUEST TO GET ACCESS TOKEN")
|
||||
|
||||
local resp, err = httpc:request_uri(
|
||||
local resp, req_err = httpc:request_uri(
|
||||
remote_url,
|
||||
{
|
||||
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
||||
@@ -36,15 +36,15 @@ local function get_access_token()
|
||||
)
|
||||
|
||||
ngx.log(ngx.INFO, "RESP -> ", pl.write(resp))
|
||||
ngx.log(ngx.ERR, "ERR -> ", err)
|
||||
ngx.log(ngx.ERR, "ERR -> ", req_err)
|
||||
|
||||
if resp == nil then
|
||||
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *HTYUC*", err)
|
||||
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *HTYUC*", req_err)
|
||||
end
|
||||
|
||||
if 200 ~= resp.status then
|
||||
ngx.log(ngx.ERR, "GET ACCESS TOKEN *FAILED*", err)
|
||||
ngx.say(err)
|
||||
ngx.log(ngx.ERR, "GET ACCESS TOKEN *FAILED*", req_err)
|
||||
ngx.say(req_err)
|
||||
ngx.exit(resp.status)
|
||||
else
|
||||
ngx.log(ngx.ERR, "RESP IS OK -> ", resp.body)
|
||||
@@ -57,24 +57,24 @@ local function get_wx_media(media_id)
|
||||
print("access token: " .. access_token)
|
||||
local wx_media_url = string.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s", access_token, media_id)
|
||||
print("wx_media_url: " .. wx_media_url)
|
||||
local res, err = httpc:request_uri(wx_media_url, {
|
||||
local resp, req_err = httpc:request_uri(wx_media_url, {
|
||||
method = 'GET',
|
||||
ssl_verify = ssl_verify or false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
||||
})
|
||||
|
||||
if res == nil then
|
||||
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *Weixin*", err)
|
||||
ngx.say(err)
|
||||
if resp == nil then
|
||||
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *Weixin*", req_err)
|
||||
ngx.say(req_err)
|
||||
ngx.exit(500)
|
||||
end
|
||||
|
||||
if 200 ~= res.status then
|
||||
ngx.log(ngx.ERR, 'GET WECHET MEDIA *FAILED*', err)
|
||||
ngx.say(err)
|
||||
ngx.exit(res.status)
|
||||
if 200 ~= resp.status then
|
||||
ngx.log(ngx.ERR, 'GET WECHET MEDIA *FAILED*', req_err)
|
||||
ngx.say(req_err)
|
||||
ngx.exit(resp.status)
|
||||
end
|
||||
|
||||
local filename = ngx.re.match(res.headers['Content-disposition'], [[filename="(.+\.([a-zA-Z0-9])+)"]], "jo")[1]
|
||||
local filename = ngx.re.match(resp.headers['Content-disposition'], [[filename="(.+\.([a-zA-Z0-9])+)"]], "jo")[1]
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
local saved_file = file_dir .. "/" .. filename;
|
||||
print('saved file...' .. saved_file);
|
||||
@@ -82,7 +82,7 @@ local function get_wx_media(media_id)
|
||||
if file == nil then
|
||||
print("Can not open file..." .. err)
|
||||
else
|
||||
file:write(res.body)
|
||||
file:write(resp.body)
|
||||
file:close()
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user