首页 > 编程知识 正文

谷歌验证码app下载,google注册收不到验证码

时间:2023-05-04 20:01:12 阅读:41746 作者:1289

因为工作需要使用谷歌验证码ReCaptcha v3,所以在网上知道。 以下是我的学习共享。

大家应该用过谷歌的验证码。 例如

在这种情况下,我们必须手动选择。 不需要ReCaptcha V3,用户不需要手动验证。

大白话:用户不用再选择哪些图里有飞机,哪些图里有汽车等。ReCaptcha V3 会在后台对用户的行为进行监测,然后会返回一个分数(0-1)之间,我们就可以自定义了,小于0.5的就是机器人,他们就需要被验证,验证手机号等。

1 .很遗憾首先去reCaptcha官网:3359 developers.Google.com/recaptcha /,但是这个网站需要翻墙。 如果你没有能力的话,那就好了。 因为我不能教你怎么翻墙。

标签随便写,这无所谓

选择版本3

域名可以写自己的域名,也可以在localhost中测试

所有者是你的谷歌账户。 我自己注册

2 .提交后,将显示客户端和服务端两个密钥

他会向你提示如何实现。 我在这里写我使用的实现方法

3 .首页html! doctypehtmlhtmlheadmetacharset=' utf-8 ' titlegooglerecaptcha/title/headbodybutton单击我执行验证/buttonscriptsrc=' ' 脚本类型=' text/JavaScript ' const captcha _ client _ secret='这里也有你的客户端密钥'; window.onload=() document.query selector (button ).addeventlistener (),)=) grecaptcha.executer { action : ' Fetch ()/validate? token=' token,{ method 3360 ' get ' }.then (响应={ if (响应. ok ) { response.json ).then ) ) message ) console.log (消息; ); }; ); ); ); (; /script/body/html重要代码

单击grecaptcha.execute (captcha _ client _ secret,{action: 'homepage'} ).then (功能(令牌) ) google ) token=' token,{ //将得到的请求发送到服务器端,服务器端进行适当处理的method : ' get ' }.then (response={ if (response.ok ) ) ); }; ); } 4.后端代码@requestmapping(/validate ) responsebodypublicstringcheck ) httpservletrequestrequest { string checkc

ode = request.getParameter("token"); String secret = "6LdTTf8cAAAAAJnW4jipqR0t03pG-84zpPwGPXfQ"; String param = "secret="+secret+"&response=" + checkCode; String json = HttpSendUtil.instance().sendPost("https://www.recaptcha.net/recaptcha/api/siteverify", param, "UTF-8"); return json; }

首先你会发现你没有这个HttpSendUtil,没关系,我有

package com.sendy.boot.controller;import java.io.*;import java.net.HttpURLConnection;import java.net.URL;public class HttpSendUtil { private HttpSendUtil() { } private static class HttpSendUtilInstance { private static final HttpSendUtil INSTANCE = new HttpSendUtil(); } public static HttpSendUtil instance() { return HttpSendUtilInstance.INSTANCE; } public String sendPost(String sendUrl, String params, String encodType) { StringBuffer receive = new StringBuffer(); HttpURLConnection URLConn = null; BufferedWriter bw = null; BufferedReader br = null; try { URL url = new URL(sendUrl); URLConn = (HttpURLConnection) url.openConnection(); URLConn.setRequestMethod("POST"); URLConn.setDoOutput(true); URLConn.setDoInput(true); URLConn.setUseCaches(false); URLConn.setAllowUserInteraction(true); HttpURLConnection.setFollowRedirects(true); URLConn.setInstanceFollowRedirects(true); URLConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); URLConn.setRequestProperty("Content-Length", String.valueOf(params.getBytes().length)); DataOutputStream dos = new DataOutputStream(URLConn.getOutputStream()); dos.writeBytes(params); br = new BufferedReader(new InputStreamReader(URLConn.getInputStream(), encodType)); String line; while ((line = br.readLine()) != null) { receive.append(line).append("rn"); } br.close(); } catch (java.io.IOException e) { receive.append("访问产生了异常-->").append(e.getMessage()); e.printStackTrace(); } finally { if (bw != null) { try { bw.close(); } catch (IOException ex) { bw = null; ex.printStackTrace(); } finally { if (URLConn != null) { URLConn.disconnect(); URLConn = null; } } } if (br != null) { try { br.close(); } catch (IOException e) { br = null; throw new RuntimeException(e); } finally { if (URLConn != null) { URLConn.disconnect(); URLConn = null; } } } } return receive.toString(); } public String sendGet(String sendUrl, String encodType) { StringBuffer receive = new StringBuffer(); BufferedReader br = null; HttpURLConnection URLConn = null; try { URL url = new URL(sendUrl); URLConn = (HttpURLConnection) url.openConnection(); URLConn.setDoInput(true); URLConn.setDoOutput(true); URLConn.connect(); URLConn.getOutputStream().flush(); br = new BufferedReader(new InputStreamReader(URLConn.getInputStream(), encodType)); String line; while ((line = br.readLine()) != null) { receive.append(line).append("rn"); } } catch (IOException e) { receive.append("访问产生了异常-->").append(e.getMessage()); e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (java.io.IOException ex) { br = null; ex.printStackTrace(); } finally { if (URLConn != null) { URLConn.disconnect(); URLConn = null; } } } } return receive.toString(); }}

上面这个代码直接用就可以

5.返回的数据

action: "homepage"challenge_ts: "2021-10-30T03:11:43Z"  //验证的时间hostname: "localhost"  //请求的地址score: 0.9  //验证得到的分数 0-1success: true  //是否验证成功

 我们可以对这个score进行自定义处理,比你得分低于0.5,你就让他进行验证,怎么验证取决于你自己

 上面的地址我都是给你们替换过的,为什么要替换?   因为你不能翻墙啊

www.google.com  替换成  www.recaptcha.net

这一步你不需要做,我在上面已经换好了。

拜拜

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。