前言
探索滑动拼图的世界!让我们一起揭开滑动拼图验证码背后的谜团,分享如何应对这个有趣而挑战性的验证方式。滑动拼图验证码已经成为了我们与数字世界互动的一部分,帮助保护着网站和应用的安全。让我们一起讨论如何轻松地解决滑动拼图验证码的挑战吧!
你最近是否遇到过令人头疼的验证码?为何不让滑动拼图成为你的新选择呢?通过完成一个有趣的滑动拼图来验证你的身份,既能锻炼大脑,又能保护你的隐私。

HTML 代码
1<script src="captcha.js"></script> 2<script> 3kg.captcha({ 4 // 绑定元素,验证框显示区域 5 bind: "#captchaBox", 6 // 验证成功事务处理 7 success: function(e) { 8 console.log(e); 9 }, 10 // 验证失败事务处理 11 failure: function(e) { 12 console.log(e); 13 }, 14 // 点击刷新按钮时触发 15 refresh: function(e) { 16 console.log(e); 17 } 18}); 19</script> 20 21<div id="captchaBox">载入中 ...</div>
Python 代码
1from wsgiref.simple_server import make_server 2from KgCaptchaSDK import KgCaptcha 3def start(environ, response): 4 # 填写你的 AppId,在应用管理中获取 5 AppID = "AppID" 6 # 填写你的 AppSecret,在应用管理中获取 7 AppSecret = "AppSecret" 8 request = KgCaptcha(AppID, AppSecret) 9 # 填写应用服务域名,在应用管理中获取 10 request.appCdn = "https://cdn.kgcaptcha.com" 11 # 请求超时时间,秒 12 request.connectTimeout = 10 13 # 用户id/登录名/手机号等信息,当安全策略中的防控等级为3时必须填写 14 request.userId = "kgCaptchaDemo" 15 # 使用其它 WEB 框架时请删除 request.parse,使用框架提供的方法获取以下相关参数 16 parseEnviron = request.parse(environ) 17 # 前端验证成功后颁发的 token,有效期为两分钟 18 request.token = parseEnviron["post"].get("kgCaptchaToken", "") # 前端 _POST["kgCaptchaToken"] 19 # 客户端IP地址 20 request.clientIp = parseEnviron["ip"] 21 # 客户端浏览器信息 22 request.clientBrowser = parseEnviron["browser"] 23 # 来路域名 24 request.domain = parseEnviron["domain"] 25 # 发送请求 26 requestResult = request.sendRequest() 27 if requestResult.code == 0: 28 # 验证通过逻辑处理 29 html = "验证通过" 30 else: 31 # 验证失败逻辑处理 32 html = f"{requestResult.msg} - {requestResult.code}" 33 response("200 OK", [("Content-type", "text/html; charset=utf-8")]) 34 return [bytes(str(html), encoding="utf-8")] 35httpd = make_server("0.0.0.0", 8088, start) # 设置调试端口 http://localhost:8088/ 36httpd.serve_forever()
最后
SDK开源地址:https://github.com/KgCaptcha,顺便做了一个演示:https://www.kgcaptcha.com/demo/