极验行为验证的使用方法

1,官方文档

  https://docs.geetest.com/install/deploy/server/python

2,使用方法(基于flask)

  1,从Github: gt3-python-sdk下载.zip文件,这个官方的压缩文件里面有三个demo,分别是基于django、flask、tornado实现的,可以作为参考。

    我们需要这里面的 geetest.py 文件、gt.js文件。

  2,在极验官网注册一个账号,获取公钥(id)、私钥(key),在后台代码中会用到。

  3,后台代码

 

from flask import Blueprint,render_template,session,request
import random

from bul.u.geetest import GeetestLib

captach_id = "7982db09811fc65bb0172e65feda8181"
private_key = "e9d4fc300d39c013e85c631ed791af3b"




jc=Blueprint('jc',__name__)



@jc.route('/index')
def index():
    return render_template('y.html')


@jc.route('/getcaptcha', methods=["GET"])
def get_captcha():
    user_id = 'test'
    gt =  GeetestLib(captach_id, private_key)
    status = gt.pre_process(user_id)
    session[gt.GT_STATUS_SESSION_KEY] = status
    session["user_id"] = user_id
    response_str = gt.get_response_str()
    return response_str

@jc.route('/validate', methods=["POST"])
def validate_capthca():
    gt = GeetestLib(captach_id, private_key)
    status = session[gt.GT_STATUS_SESSION_KEY]
    challenge = request.form[gt.FN_CHALLENGE]
    validate = request.form[gt.FN_VALIDATE]
    seccode = request.form[gt.FN_SECCODE]
    user_id = session["user_id"]
    if status:
        result = gt.success_validate(challenge, validate, seccode, user_id)
    else:
        result = gt.failback_validate(challenge, validate, seccode)
    result = "success" if result else "fail"
    return result
View Code

 

  4,前端配置

 


"zh-CN">

    "UTF-8">
    "viewport" content="width=device-width, initial-scale=1">
    Sliding mode
    


Sliding mode

"form">
class="inp" id="username" type="text" value="username">

class="inp" id="password" type="password" value="123456">

"captcha">
"text"> 行为验证™ 安全组件加载中
"wait" class="show">
class="loading">
class="loading-dot">
class="loading-dot">
class="loading-dot">
class="loading-dot">

"btn" class="btn">Submit
View Code

 

 

 

 

    

    

转载于:https://www.cnblogs.com/glf1160/p/10114330.html

你可能感兴趣的:(极验行为验证的使用方法)