VAPTCHA

VAPTCHA Python SDK


Keywords
vaptcha-python-sdk
Install
pip install VAPTCHA==1.0.0

Documentation

vaptcha-python-sdk

Step1.环境准备

  • Vaptcha Python SDK 兼容python2.7+,如有较低版本用户,请联系vaptcha技术支持。目前提供基于WSGI服务器的DEMO。

  • 要使用Vaptcha Python SDK,你需要一个Vaptcha账号、一个验证单元以及一对VID和Key。请在Vaptcha验证管理后台查看。

Step2.SDK获取和安装

  • 使用git命令获取

    git clone https://github.com/vaptcha/vaptcha-python-sdk.git

    github地址手动下载获取

  • 直接使用pip安装

    pip install vaptchasdk
  • 或进入/vaptcha-python-sdk目录,本地安装

    也许你需要sudo命令,或者管理员身份下运行该命令

     python setup.py install
  • 引入vaptcha

    from vaptchasdk import vaptcha
  • 配置vidkey并创建vaptcha对象

    vid, key = 'xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx'
    _vaptcha = vaptcha(vid, key)
    
  • 运行demo

    demo中的vid和key使用的是vaptcha官方为demo免费提供的,缺少一些限制,可能存在安全隐患。在实际生产环境中,我们建议你登陆vaptcha管理后台,在验证管理中添加对应的验证单元,并把domain参数设置为实际环境中的域名。

    进入/vaptcha-python-sdk/demo目录,运行如下命令,并在http://localhost:4396中查看

    python server.py

Step3.SDK接口说明

​ SDK提供以下三个接口:

  • get_challenge(scene_id='')

    获取流水号接口,用于获取vid和challenge

    参数:

    scene_id:场景id,请在vaptcha管理后台查看,类型:字符串,选填

    返回值:json字符串

    example:

    result = _vaptcha.get_challenge()
  • downtime(data)

    宕机模式接口,用户宕机模式的相关验证,仅用于和vaptcha客户端sdk交互

    参数:

    data:由vapthca客户端sdk回传,类型:字符串

    返回值:json字符串

    example:

    result = _vaptcha.downtime(data)
  • validate(challenge,token,scene_id='')

    二次验证接口,用于与vaptcha服务器的二次验证。

    参数:

    challenge:由用户客户端回传,类型:字符串

    token:由用户客户端回传,类型:字符串

    scene_id:由用户配置,与get_challenge接口的scene_id一致,类型:字符串,选填

    返回值:bool类型

    example:

    result = _vaptcha.validate(challenge, token)