【记】滑动拼图验证码在搜索中的作用
作者:宙哈哈
- 2023-03-15 广东
本文字数:1122 字
阅读完需:约 4 分钟
开头
验证码应用于我们生活、工作的方方面面,比如注册登录账号、支付订单、修改密码等。下面我是在一次项目中利用滑动拼图验证码和搜索功能“合作共赢”的记录。
验证码展示
具体实现
前端代码
// 引入js<script src="captcha.js?appid=XXX"></script><script>kg.captcha({ // 绑定弹窗按钮 button: "#captchaButton",
// 验证成功事务处理 success: function (e) { // 验证成功,直接提交表单 // form1.submit(); console.log(e); },
// 验证失败事务处理 failure: function (e) { console.log(e); },
// 点击刷新按钮时触发 refresh: function (e) { console.log(e); }});</script>
<a id="captchaButton"></a>
复制代码
验证结果说明
Python 代码
from wsgiref.simple_server import make_serverfrom KgCaptchaSDK import KgCaptchadef start(environ, response): # 填写你的 AppId,在应用管理中获取 AppID = "AppId" # 填写你的 AppSecret,在应用管理中获取 AppSecret = "AppSecret" request = KgCaptcha(AppID, AppSecret) # 填写应用服务域名,在应用管理中获取 request.appCdn = "https://cdn.kgcaptcha.com" # 请求超时时间,秒 request.connectTimeout = 10 # 用户id/登录名/手机号等信息,当安全策略中的防控等级为3时必须填写 request.userId = "kgCaptchaDemo" # 使用其它 WEB 框架时请删除 request.parse,使用框架提供的方法获取以下相关参数 parseEnviron = request.parse(environ) # 前端验证成功后颁发的 token,有效期为两分钟 request.token = parseEnviron["post"].get("kgCaptchaToken", "") # 前端 _POST["kgCaptchaToken"] # 客户端IP地址 request.clientIp = parseEnviron["ip"] # 客户端浏览器信息 request.clientBrowser = parseEnviron["browser"] # 来路域名 request.domain = parseEnviron["domain"] # 发送请求 requestResult = request.sendRequest() if requestResult.code == 0: # 验证通过逻辑处理 html = "验证通过" else: # 验证失败逻辑处理 html = f"{requestResult.msg} - {requestResult.code}" response("200 OK", [("Content-type", "text/html; charset=utf-8")]) return [bytes(str(html), encoding="utf-8")]httpd = make_server("0.0.0.0", 8088, start) # 设置调试端口 http://localhost:8088/httpd.serve_forever()
复制代码
最后
SDK 开源地址:https://github.com/KgCaptcha,顺便做了一个演示:https://www.kgcaptcha.com/demo/
划线
评论
复制
发布于: 刚刚阅读数: 5
宙哈哈
关注
还未添加个人签名 2023-03-09 加入
还未添加个人简介










评论