Skip to main content

Flask-DXCaptcha是依赖顶象科技提供的无感验证功能开发的Flask 扩展

Project description

Flask-DXCaptcha是依赖顶象科技提供的无感验证功能开发的Flask 扩展

安装Flask-DXCaptcha

使用 pip 安装

pip install Flask-DXCaptcha

配置

the-config.cfg 文件添加配置项

DX_APP_ID = 'xxx' # APP_ID
DX_APP_SECRECT = 'xxx' # APP_SECRECT

APP_ID和APP_SECRECT需要从 顶象科技官网 获取

跟其他扩展使用的方式类似,简单介绍如下

from flask_dxcaptcha import DXCaptcha

app = Flask(__name__)
app.config.from_pyfile('the-config.cfg')
dxcaptcha = DXCaptcha(app)

或者

from flask import Flask
from flask_dxcaptcha import DXCaptcha
dxcaptcha = DXCaptcha()
...
app = Flask(__name__)
app.config.from_pyfile('the-config.cfg')
dxcaptcha.init_app(app)

如何使用

dxcaptcha.client.setTimeOut(2)

response = dxcaptcha.client.checkToken(v_token)

if response['serverStatus'] == 'SERVER_SUCCESS':
    if response['result'] is False:
        pass
        # token验证失败,业务系统可以直接阻断该次请求或者继续弹验证码
        # 具体的实现逻辑
else:
    pass
    # '提交验证失败,请重新提交'
    # 具体的实现逻辑

v_token 值的获取可以参考 官网 文档,下面仅是示例

html

<form>
  <div id='c1'></div>
  <input id='v_token' name='v_token' />
</form>

javascript

<script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js"></script>

<script type='text/javascript'>
var myCaptcha = _dx.Captcha(document.getElementById('c1'), {
  appId: 'appId', // appId
  style: 'popup',
  width: '100%',
  success: function (token) {
    document.getElementById('v_token').value = token;
    myCaptcha.hide();
  }
});
myCaptcha.show();
</script>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-DXCaptcha, version 1.0.8
Filename, size File type Python version Upload date Hashes
Filename, size Flask_DXCaptcha-1.0.8-py3-none-any.whl (10.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size Flask-DXCaptcha-1.0.8.tar.gz (6.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page