https://github.com/GeeTeam/gt3-python-sdk

python setup.py install

复制sdk文件至项目目录

views.py

from geetest.geetest import GeetestLib
from django.template import RequestContext
import json
pc_geetest_id = "
pc_geetest_key = "
mobile_geetest_id = "
mobile_geetest_key = "
def home(request):return render(request,"test.html")def pcgetcaptcha(request):user_id = 'test'gt = GeetestLib(pc_geetest_id, pc_geetest_key)status = gt.pre_process(user_id)request.session[gt.GT_STATUS_SESSION_KEY] = statusrequest.session["user_id"] = user_idresponse_str = gt.get_response_str()return HttpResponse(response_str)def mobilegetcaptcha(request):user_id = 'test'gt = GeetestLib(mobile_geetest_id, mobile_geetest_key)status = gt.pre_process(user_id)request.session[gt.GT_STATUS_SESSION_KEY] = statusrequest.session["user_id"] = user_idresponse_str = gt.get_response_str()return HttpResponse(response_str)def pcvalidate(request):if request.method == "POST":gt = GeetestLib(pc_geetest_id, pc_geetest_key)challenge = request.POST.get(gt.FN_CHALLENGE, '')validate = request.POST.get(gt.FN_VALIDATE, '')seccode = request.POST.get(gt.FN_SECCODE, '')status = request.session[gt.GT_STATUS_SESSION_KEY]user_id = request.session["user_id"]if status:result = gt.success_validate(challenge, validate, seccode, user_id)else:result = gt.failback_validate(challenge, validate, seccode)result = "<html><body><h1>登录成功</h1></body></html>" if result else "<html><body><h1>登录失败</h1></body></html>"return HttpResponse(result)return HttpResponse("error")def pcajax_validate(request):if request.method == "POST":gt = GeetestLib(pc_geetest_id, pc_geetest_key)challenge = request.POST.get(gt.FN_CHALLENGE, '')validate = request.POST.get(gt.FN_VALIDATE, '')seccode = request.POST.get(gt.FN_SECCODE, '')status = request.session[gt.GT_STATUS_SESSION_KEY]user_id = request.session["user_id"]if status:result = gt.success_validate(challenge, validate, seccode, user_id)else:result = gt.failback_validate(challenge, validate, seccode)result = {"status":"success"} if result else {"status":"fail"}return HttpResponse(json.dumps(result))return HttpResponse("error")def mobileajax_validate(request):if request.method == "POST":gt = GeetestLib(mobile_geetest_id, mobile_geetest_key)challenge = request.POST.get(gt.FN_CHALLENGE, '')validate = request.POST.get(gt.FN_VALIDATE, '')seccode = request.POST.get(gt.FN_SECCODE, '')status = request.session[gt.GT_STATUS_SESSION_KEY]user_id = request.session["user_id"]if status:result = gt.success_validate(challenge, validate, seccode, user_id)else:result = gt.failback_validate(challenge, validate, seccode)result = {"status":"success"} if result else {"status":"fail"}return HttpResponse(json.dumps(result))return HttpResponse("error")

urls.py

from users.views import pcgetcaptcha,mobilegetcaptcha,pcvalidate,pcajax_validate,mobileajax_validate,home
    url(r'^pc-geetest/register', pcgetcaptcha, name='pcgetcaptcha'),url(r'^mobile-geetest/register', mobilegetcaptcha, name='mobilegetcaptcha'),url(r'^pc-geetest/validate$', pcvalidate, name='pcvalidate'),url(r'^pc-geetest/ajax_validate', pcajax_validate, name='pcajax_validate'),url(r'^mobile-geetest/ajax_validate', mobileajax_validate, name='mobileajax_validate'),url(r'^test/', home, name='home'),

test.html

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>gt-python-django-demo</title><style>body {margin: 50px 0;text-align: center;}.inp {border: 1px solid gray;padding: 0 10px;width: 200px;height: 30px;font-size: 18px;}.btn {border: 1px solid gray;width: 100px;height: 30px;font-size: 18px;cursor: pointer;}#embed-captcha {width: 300px;margin: 0 auto;}.show {display: block;}.hide {display: none;}#notice {color: red;}/* 以下遮罩层为demo.用户可自行设计实现 */#mask {display: none;position: fixed;text-align: center;left: 0;top: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.5);overflow: auto;}/* 可自行设计实现captcha的位置大小 */.popup-mobile {position: relative;}#popup-captcha-mobile {position: fixed;display: none;left: 50%;top: 50%;transform: translate(-50%, -50%);-webkit-transform: translate(-50%, -50%);z-index: 9999;}</style>
</head>
<body>
<h1>极验验证SDKDemo</h1>
<br><br>
<hr>
<br><br><!-- 为使用方便,直接使用jquery.js库,如您代码中不需要,可以去掉 -->
<script src="http://code.jquery.com/jquery-1.12.3.min.js"></script>
<!-- 引入封装了failback的接口--initGeetest -->
<script src="http://static.geetest.com/static/tools/gt.js"></script><!-- 若是https,使用以下接口 -->
<!-- <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> -->
<!-- <script src="https://static.geetest.com/static/tools/gt.js"></script> --><div class="popup"><h2>弹出式Demo,使用ajax形式提交二次验证码所需的验证结果值</h2><br><p><labe>用户名:</labe><input id="username1" class="inp" type="text" value="极验验证"></p><br><p><label>密    码:</label><input id="password1" class="inp" type="password" value="123456"></p><br><input class="btn" id="popup-submit" type="submit" value="提交"><div id="popup-captcha"></div>
</div><script>var handlerPopup = function (captchaObj) {// 成功的回调captchaObj.onSuccess(function () {var validate = captchaObj.getValidate();$.ajax({url: "/pc-geetest/ajax_validate", // 进行二次验证type: "post",dataType: "json",data: {username: $('#username1').val(),password: $('#password1').val(),geetest_challenge: validate.geetest_challenge,geetest_validate: validate.geetest_validate,geetest_seccode: validate.geetest_seccode},success: function (data) {if (data && (data.status === "success")) {$(document.body).html('<h1>登录成功</h1>');} else {$(document.body).html('<h1>登录失败</h1>');}}});});$("#popup-submit").click(function () {captchaObj.show();});// 将验证码加到id为captcha的元素里captchaObj.appendTo("#popup-captcha");// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html};// 验证开始需要向网站主后台获取id,challenge,success(是否启用failback)$.ajax({url: "/pc-geetest/register?t=" + (new Date()).getTime(), // 加随机数防止缓存type: "get",dataType: "json",success: function (data) {// 使用initGeetest接口// 参数1:配置参数// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件initGeetest({gt: data.gt,challenge: data.challenge,product: "popup", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config}, handlerPopup);}});
</script>
<br><br>
<hr>
<br><br>
<form class="popup" action="/pc-geetest/validate" method="post"><h2>嵌入式Demo,使用表单形式提交二次验证所需的验证结果值</h2><br><p><label for="username2">用户名:</label><input class="inp" id="username2" type="text" value="极验验证"></p><br><p><label for="password2">密    码:</label><input class="inp" id="password2" type="password" value="123456"></p><div id="embed-captcha"></div><p id="wait" class="show">正在加载验证码......</p><p id="notice" class="hide">请先拖动验证码到相应位置</p><br><input class="btn" id="embed-submit" type="submit" value="提交">
</form><script>var handlerEmbed = function (captchaObj) {$("#embed-submit").click(function (e) {var validate = captchaObj.getValidate();if (!validate) {$("#notice")[0].className = "show";setTimeout(function () {$("#notice")[0].className = "hide";}, 2000);e.preventDefault();}});// 将验证码加到id为captcha的元素里,同时会有三个input的值:geetest_challenge, geetest_validate, geetest_seccodecaptchaObj.appendTo("#embed-captcha");captchaObj.onReady(function () {$("#wait")[0].className = "hide";});// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html};$.ajax({// 获取id,challenge,success(是否启用failback)url: "/pc-geetest/register?t=" + (new Date()).getTime(), // 加随机数防止缓存type: "get",dataType: "json",success: function (data) {// 使用initGeetest接口// 参数1:配置参数// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件initGeetest({gt: data.gt,challenge: data.challenge,product: "embed", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config}, handlerEmbed);}});
</script>
<br><br>
<hr>
<br><br>
<div class="popup-mobile"><h2>移动端手动实现弹出式Demo</h2><br><p><labe for="username3">用户名:</labe><input id="username3" class="inp" type="text" value="极验验证"></p><br><p><label for="password3">密    码:</label><input id="password3" class="inp" type="password" value="123456"></p><br><input class="btn" id="popup-submit-mobile" type="submit" value="提交"><div id="mask"></div><div id="popup-captcha-mobile"></div>
</div><script>$("#mask").click(function () {$("#mask, #popup-captcha-mobile").hide();});$("#popup-submit-mobile").click(function () {$("#mask, #popup-captcha-mobile").show();});var handlerPopupMobile = function (captchaObj) {// 将验证码加到id为captcha的元素里captchaObj.appendTo("#popup-captcha-mobile");//拖动验证成功后两秒(可自行设置时间)自动发生跳转等行为captchaObj.onSuccess(function () {var validate = captchaObj.getValidate();$.ajax({url: "/mobile-geetest/ajax_validate", // 进行二次验证type: "post",dataType: "json",data: {// 二次验证所需的三个值username: $('#username3').val(),password: $('#password3').val(),geetest_challenge: validate.geetest_challenge,geetest_validate: validate.geetest_validate,geetest_seccode: validate.geetest_seccode},success: function (data) {if (data && (data.status === "success")) {$(document.body).html('<h1>登录成功</h1>');} else {$(document.body).html('<h1>登录失败</h1>');}}});});// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html};$.ajax({// 获取id,challenge,success(是否启用failback)url: "/mobile-geetest/register?t=" + (new Date()).getTime(), // 加随机数防止缓存type: "get",dataType: "json",success: function (data) {// 使用initGeetest接口// 参数1:配置参数// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件initGeetest({gt: data.gt,challenge: data.challenge,offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config}, handlerPopupMobile);}});
</script>
</body>
</html>

Django geetest相关推荐

  1. Django中使用极验Geetest滑动验证码

    一,环境部署 1.创建一个django测试项目 此处省略... 二,文档部署 1.下载安装python对应的SDK 使用命令从Github导入完整项目:git clone https://github ...

  2. Django中使用极验Geetest滑动验证码过程解析

    **一,环境部署 ** 1.创建一个django测试项目 二,文档部署 1.下载安装python对应的SDK 使用命令从Github导入完整项目:git clone https://github.co ...

  3. 给html5添加极验,Django中使用极验Geetest滑动验证码过程解析

    一,环境部署 1.创建一个django测试项目 二,文档部署 1.下载安装python对应的SDK 使用命令从Github导入完整项目:git clone https://github.com/Gee ...

  4. Django之BBS博客项目

    一.登陆功能(验证码) 1 from geetest importGeetestLib2 from django.contrib importauth3 4 #使用极验滑动验证码的登陆 5 deflo ...

  5. Django 项目试炼blog(10) --补充 滑动验证码

    首先安装一个需要用到的模块 pip install social-auth-app-django 安装完后在终端输入pip list会看到 social-auth-app-django 3.1.0 s ...

  6. Django项目实现验证码

    1. django-simple-captcha 模块 安装 django-simple-captcha pip install django-simple-captcha pip install P ...

  7. Django 之验证码实现

    1. django-simple-captcha 模块 安装 django-simple-captcha pip install django-simple-captcha pip install P ...

  8. 插件3-滑动验证(geetest)

    一.说明 1.geetest网站:https://docs.geetest.com/install/deploy/server/python 2.安装geetest : pip install gee ...

  9. django滑动验证码

    一.概述 最近用django写了一个后台系统,使用的是验证码方式.但是开发人员抱怨,输入验证太麻烦,还有可能出错,太影响效率了. 是否可以用滑动验证码,一拖动就可以了! 网上大部分文章,用的是极验Ge ...

最新文章

  1. Find Code for Research Papers
  2. 2021吉林市高考成绩查询系统,吉林省教育考试院高考成绩查询系统入口2021
  3. 统计输入的汉字,数字,英文,other数量
  4. UA OPTI570 量子力学 Quasi-classical states与Displacement Operator
  5. LauncherApplication
  6. 步进电机控制芯片_STK682/步进电机_STK682-010-E控制芯片 原创中文翻译
  7. linux 基本指令
  8. jsp java el表达式_jsp相关笔记,el表达式、jsp标签库(jstl)
  9. logisim优先编码器怎么用_编码器简介、应用的stm32代码及注释
  10. PP视频如何设置默认缓存个数
  11. git(5)---Git 与Repo 管理Android代码
  12. python正则表达式 身份证_正则表达式实现身份证信息验证
  13. c语言字体透明背景,背景透明文字不透明的最佳方法兼容IE(以背景黑色透明度0.5为例)...
  14. c++ primer plus第六版复习题及答案
  15. 关于如何将多个Cpp文件关联起来
  16. standard fifo和fwft fifo的区别
  17. 201912月全国计算机二级考试,201912月天津计算机二级报名时间:12月5日-12月7日!附报名入口...
  18. 2011QQ搞笑个性签名:小弟不才,大名耶稣.小名上帝.法号如来
  19. python for in range 什么意思_python中range什么意思,
  20. Java基础知识面试题(总结最全面的面试题)

热门文章

  1. 乳制品追溯系统实现的好处
  2. 复变函数不挂科——3小时学完复变函数与积分变换(猴博士复变函数学习笔记1)
  3. itext html转换pdf,itext转换html成pdf(支持中文、图片)
  4. MYIE2拖拽搜索中文关键词google乱码的解决方法
  5. 前端中一些对齐方式的解析
  6. 最好的医生是自己:把吃出来的病吃回去
  7. 弘基笔记本拆机加内存条
  8. 养成励志的习惯,一生励志
  9. ActorBeginOverlap
  10. openerp 索引