如何使用 react-google-recaptcha 重置 Google recaptcha

Inq*_*irl 9 captcha recaptcha reactjs redux redux-form

看起来 google recaptcha 的工作方式是,如果使用特定令牌进行了验证尝试,则无法再次使用。

文档指出“您将需要调用 grecaptcha.reset() 以要求最终用户再次使用 reCAPTCHA 进行验证”

我正在尝试使用 react-google-recaptcha npm 包尝试此操作。

这是我的代码:

function onChange(grecaptcha) {
  console.log(grecaptcha);
  grecaptcha.reset(); // this doesn't work
}

class Captcha extends React.Component {
  render() {
    return <div>
      <Recaptcha
          sitekey='#'
          onChange={onChange(this)}
      /> </div> 
  }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用带有响应和秘密值的 google api https://www.google.com/recaptcha/api/siteverify进行服务器端验证时,成功响应在第一次验证后始终评估为“false”。为了防止这种情况,我按照文档中的建议重置了 grecaptcha,但它不起作用。

有什么我想念的吗?

提前致谢

编辑:

https://github.com/dozoisch/react-google-recaptcha提供了 reset() 实用程序函数,这是我在用户解决验证码后尝试调用的函数,想知道我是否没有正确调用它。

Skä*_*nen 11

我遇到了类似的问题,不得不将其更改为:

window.grecaptcha.reset();
Run Code Online (Sandbox Code Playgroud)


sar*_*eeh 7

你可以试试Reaptcha

在处理 reCAPTCHA 时,它比react-google-recaptcha.

引用文档:

<Reaptcha
  ref={e => (this.captcha = e)}
  sitekey="YOUR_API_KEY"
  onVerify={() => {
    // Do something
  }}
/>
<button onClick={this.captcha.reset}>
  Reset
</button>
Run Code Online (Sandbox Code Playgroud)