具有 Spring 安全性的 Recaptcha

Recaptcha with Spring Security

不幸的是,我在 localhost 上没有为我的应用程序使用 Recaptcha。我关注了 Baeldung 上的介绍。我为 localhost127.0.0.1 创建了一个网站密钥和密码。

在我的 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>`

但我总是收到无效网站密钥的错误消息:

我能做什么?感谢您的提示。

我让它工作了,它也可以在本地主机上工作。首先,如果您创建一个新的 API 密钥,我想它可能需要几次才能真正激活。

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

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

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

API 仍注册为 localhost127.0.0.1

不,我有类似的东西:

我遇到的另一个解决方案是使用 recaptcha-spring-boot-starter。它大大减少了我的代码,但我只通过 Recaptcha V2 获得了它 运行。但这对我来说也可以:

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