Recaptcha与Spring Security

问题描述 投票:0回答:2

不幸的是,我没有让Recaptcha为localhost上的应用程序工作。我跟着Baeldung的介绍。我为localhost127.0.0.1创建了一个网站密钥和秘密。

enter image description here

在我的html头中有脚本src:

 `<script src="https://www.google.com/recaptcha/api.js"></script>`

recaptcha的div看起来像:

`<div class="g-recaptcha" data-sitekey="6Le_LZgUAAAAAKlzsoEBOOQvCOqIr7r65eiN4bd4">recaptcha</div>`
`<span id="captchaError" class="alert alert-danger " style="display:none"></span>`

但我总是得到一个错误的无效网站密钥:

enter image description here

我能做什么?谢谢你的提示。

spring-security recaptcha
2个回答
1
投票

我得到了它的工作,它也适用于localhost。首先,如果你创建一个新的API密钥,我想它可能需要几次真正激活。

在我的页面上,我现在做了以下:

`<script src='https://www.google.com/recaptcha/api.js?render=6Le_LZgUAAAAAM5uw_9hujkS6SjBWLNVkQOvewWf'></script>`

我完全删除了<div class="g-recaptcha" ...(见问题)。

API仍然在localhost127.0.0.1注册

不,我有类似的东西:

enter image description here


1
投票

我遇到的另一个解决方案是使用recaptcha-spring-boot-starter。它大大减少了我的代码,但我只使用了Recaptcha V2。但那对我也没关系:

https://github.com/mkopylec/recaptcha-spring-boot-starter-samples

© www.soinside.com 2019 - 2024. All rights reserved.