使用不帶任何插件的reCaptcha並不難。請參閱here for how to display reCaptcha without plugins和here for how to verify the user's answer。該API非常簡單。當用戶解決驗證碼時,將提交兩個參數:recaptcha_challenge_field
和recaptcha_response_field
。您可以使用它們從服務器調用驗證API,並檢查解決方案是否正常。例如:
require 'net/http'
require 'json'
post '/check_captcha' do
res = Net::HTTP.post_form(
URI.parse('http://www.google.com/recaptcha/api/verify'),
{
'privatekey' => 'Your private key',
'remoteip' => request.ip,
'challenge' => params[:recaptcha_challenge_field],
'response' => params[:recaptcha_response_field]
}
)
success, error_key = res.body.lines.map(&:chomp)
if success == 'true'
# solved the captcha
else
# did not solve the captcha
end
end
謝謝@ p11y! –