如何知道 reCAPTCHA v3 是不是有效?
Posted
技术标签:
【中文标题】如何知道 reCAPTCHA v3 是不是有效?【英文标题】:How to know if reCAPTCHA v3 works or not?如何知道 reCAPTCHA v3 是否有效? 【发布时间】:2020-03-12 21:38:19 【问题描述】:我的前端是这样使用 vuetify 的:
validate: async function ()
let tokenCaptcha
await this.$recaptcha('login').then((token) =>
tokenCaptcha = token
)
if (this.$refs.form.validate() && tokenCaptcha)
let params =
birthDate: this.birthday,
emailAddress: this.email,
name: this.fullname,
phoneNumber: this.phone,
recaptcha: tokenCaptcha
this.modalSummary = true
await this.setSummary(params) // Async vuex store / post to api backend
if (this.dataSummary)
this.success = true
else
this.success = false
参考:https://www.npmjs.com/package/vue-recaptcha-v3
我的后端/服务器端使用这样的 express js(node js):
app.post('/summary', function (req, res)
if (req.body.recaptcha === undefined || req.body.recaptcha === '' || req.body.recaptcha === null)
res.send(success: false, msg: 'Please select captcha first');
return;
const secretKey = 'xxxxxx';
const verificationURL = `https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$req.body.recaptcha&remoteip=$req.connection.remoteAddress`;
https.get(verificationURL, (resG) =>
let rawData = '';
resG.on('data', (chunk) => rawData += chunk )
resG.on('end', function()
try
var parsedData = JSON.parse(rawData);
if (parsedData.success === true)
let data =
date_of_birth: req.body.birthDate,
email_address: req.body.emailAddress,
full_name: req.body.name,
phone_number: req.body.phoneNumber,
let sql = "INSERT INTO summary SET ?";
let query = conn.query(sql, data,(err, results) =>
if(err) throw err;
res.send(success: "OK", message: 'Success', data: data);
);
else
res.send(success: false, msg: 'Failed captcha verification');
return;
catch (e)
res.send(success: false, msg: 'Failed captcha verification from Google');
return;
);
);
);
代码有效。但是如何知道 reCAPTCHA v3 是否有效?
因为没有出现第 3 版验证码。我只是想确定我的代码流是否正确。除此之外,我想检查验证码是否是机器人出现
【问题讨论】:
【参考方案1】:在网页上(右下),您应该有如下 Google Captcha 图标:
您可以在管理页面(https://www.google.com/recaptcha/about/)中验证命中数和分数分布
【讨论】:
【参考方案2】:您还可以将令牌登录到控制台。 每次发送表单时都会生成不同的令牌 - 这样您就知道验证码 v3 有效。
简单地说:
console.log(token);
Yuu 应该在控制台中输入这种类型的 unigue 字符串: enter image description here
【讨论】:
【参考方案3】:-
在用户界面(右下)你应该有这个:
-
在后端:获取recaptcha 响应的结果。喜欢:
console.info(parsedData)
必须看起来像:
"success": true|false, // whether this request was a valid reCAPTCHA token for your site
"score": number // the score for this request (0.0 - 1.0)
"action": string // the action name for this request (important to verify)
"challenge_ts": timestamp, // timestamp of the challenge load (ISO format yyyy-MM-dd'T'HH:mm:ssZZ)
"hostname": string, // the hostname of the site where the reCAPTCHA was solved
"error-codes": [...] // optional
^https://developers.google.com/recaptcha/docs/v3#site_verify_response
【讨论】:
评论不用于扩展讨论;这个对话是moved to chat。以上是关于如何知道 reCAPTCHA v3 是不是有效?的主要内容,如果未能解决你的问题,请参考以下文章
带有 Google Recaptcha v3 的 Django 联系表
reCAPTCHA v3 - 错误:没有reCAPTCHA客户端
Google reCaptcha v3 与 google reCaptcha Enterprise