【发布时间】:2021-02-18 19:55:17
【问题描述】:
我正在尝试使用我找到的代码并且它无法正常工作它总是说我是一个机器人你知道为什么这不起作用吗? Application.cfc 中包含站点和密钥。
<script src="https://www.google.com/recaptcha/api.js?render=<cfoutput>#application.SiteKey#</cfoutput>"></script>
<cfif ISDEFINED('FORM.FirstName')> <!--- check if form was submitted and if so run code below --->
<cfhttp url="https://www.google.com/recaptcha/api/siteverify?secret=#application.SecretKey#&response=#FORM['g-recaptcha-response']#" result="Response" />
<cfset Return = deserializeJSON(Response.FileContent) />
<cfif Return.success IS 'true' AND Return.score GT 0.0> <!--- check if true and if score is greater than 0.5. Run code below if all good. --->
<cfoutput>Human: #FORM.FirstName# #FORM.LastName#</cfoutput>
<!--- you can do database entry and/or email results here --->
<cfelse> <!--- if not a human, do this. I usually remove the else part completely, but if you need to do something with the robot, do it here. --->
Most likely a robot.
</cfif>
<cfelse> <!--- show form --->
<form method="post" action="/contact.cfm"> <!--- submit form back to itself --->
First Name: <input name="FirstName" type="text"><br>
Last Name: <input name="LastName" type="text"><br>
<input name="submit" type="submit">
<input name="g-recaptcha-response" id="g-recaptcha-response" type="hidden" /> <!--- javascript below gives this a value from google. --->
</form>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('<cfoutput>#application.SiteKey#</cfoutput>', {action: 'homepage'})
.then(function(token) {
document.getElementById('g-recaptcha-response').value=token;
});
});
</script>
</cfif>
【问题讨论】:
-
您查看过 HTTP 响应吗?是否有错误消息返回或只是验证失败?此外,当我实现 ReCaptcha 时,我将密钥和响应作为 CFHTTPPARAM 表单字段发送到 API。我不知道是否必须这样做,但它对我有用,所以,可能值得尝试。
-
您介意与我分享您的代码,看看我是否可以使用它。有一段时间我一直在思考这个问题。我对减少垃圾邮件的新想法持开放态度。
-
我认为我们需要看看
Response.FileContent在不成功时是什么。目前,cfelseMost likely a robot.块将隐藏有助于排除故障的信息。 -
{ "success": false, "error-codes": [ "missing-input-response" ] }
-
api 文档说 cfhttp 方法应该是 POST。您正在使用 GET developers.google.com/recaptcha/docs/verify
标签: coldfusion