我incorrect-captcha-sol在使用 Google reCAPTCHA 服务器端验证 api 时有时会收到错误代码。
我已将 google recaptcha 验证集成到我的一些 api 中。
为此,我在来自客户端的这些 api 请求上传递了 recaptcha 令牌,然后通过遵循服务器端的 recaptcha验证在服务器端对其进行验证。
我通过执行以下代码获取 recaptcha 令牌并将此令牌传递给我的 api 请求标头:
const getRecapthcaToken = () => {
return new Promise((resolve, reject) => {
try {
if (window.grecaptcha && typeof window.grecaptcha.execute === "function") {
grecaptchaExecute(window.grecaptcha.execute);
} else {
window.grecaptcha.ready(async () => {
grecaptchaExecute(window.grecaptcha.execute);
});
}
// grecaptcha execute action
async function grecaptchaExecute(ExecuteAction) {
const captchaToken = await ExecuteAction(
xxxxxx, // my …Run Code Online (Sandbox Code Playgroud) recaptcha-v3 ×1