function googleRecaptchaFinalizing(userResponseToken)
local config = require("ps.admin_config")
local json = require("cjson")
local ltn12 = require 'ltn12'
local http = require("socket.http")
http.TIMEOUT = 10
local respbody = {}
local payload =[[secret=]] .. config.captcha_private_key .. [[&response=]] .. userResponseToken .. [[&remoteip=]] .. ngx.var.remote_addr
--I Can Use ngx.escape_uri(value) to convert values to escaped type
-- ngx.log(ngx.DEBUG,"------> " .. payload)
local success , code, respHeader, status = http.request
{
url = config.google_recaptcha_validation_url
--url = config.google_recaptcha_validation_url .. "?secret="..config.captcha_private_key .. "&response=" .. userResponseToken
,method = "post",
headers =
{
["cache-control"] = "no-cache",
-- ["Content-Type"] ="application/json"
-- ["Content-Type"] ="application/x-www-form-urlencoded",
["Content-Length"] = #payload --string.len(payload)
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(respbody)
}
respbody = table.concat(respbody)
ngx.log(ngx.DEBUG,"token>>>>> " .. userResponseToken)
ngx.log(ngx.DEBUG,'success:' .. tostring(success or -1))
ngx.log(ngx.DEBUG,'code:' .. tostring(code))
ngx.log(ngx.DEBUG,'status: ' .. tostring(status))
ngx.log(ngx.DEBUG,'payload: ' .. (payloadStr or ""))
ngx.log(ngx.DEBUG,'respBody: ' .. tostring(respbody))
for k, v in pairs(respHeader) do
local attKey = tostring(k)
local attVal = tostring(v)
ngx.log(ngx.DEBUG,attKey .. " ----> " .. attVal)
end
if tostring(code)=="200" then
local jsonResp = json.decode(respbody)
if jsonResp.success == true then
return true , "is OK"
else
return false , jsonResp["error-codes"][0]
end
else
return nil , "response status code is: " .. tostring(code)
end
end
the result status code is
success:1
code:405