local M = {} local http = require "resty.http" local cjson = require "cjson" function M.get_code (antibot_uri, recaptcha_sitekey) return string.format([[
]], recaptcha_sitekey, antibot_uri, recaptcha_sitekey) end function M.check (token, recaptcha_secret) local httpc = http.new() local res, err = httpc:request_uri("https://www.google.com/recaptcha/api/siteverify", { ssl_verify = false, method = "POST", body = "secret=" .. recaptcha_secret .. "&response=" .. token .. "&remoteip=" .. ngx.var.remote_addr, headers = { ["Content-Type"] = "application/x-www-form-urlencoded" } }) if not res then return 0.0 end local data = cjson.decode(res.body) if not data.success then return 0.0 end return data.score end return M