GeeTest3.0使用教程

官方网站

前端

准备工作:确保已经在极验用户后台获取到了 captchaId

配置参数

1.引入初始化函数

<script src="https://static.geetest.com/static/js/gt.0.4.9.js"></script>

2.初始化

<div id="captcha"></div>
ajax({
  url: "API1接口(详见服务端部署)",
  type: "get",
  dataType: "json",
  success: function (data) {
    //请检测data的数据结构, 保证data.gt, data.challenge, data.success有值
    initGeetest(
      {
        // 以下配置参数来自服务端 SDK
        gt: data.gt,
        challenge: data.challenge,
        offline: !data.success,
        new_captcha: true,
      },
      function (captchaObj) {
        captchaObj.appendTo("#captcha");
      }
    );
  },
});

3.二次验证

initGeetest(
  {
    // 省略配置参数
  },
  function (captchaObj) {
    // 省略其他方法的调用
    captchaObj.onSuccess(function () {
      var result = captchaObj.getValidate();
      // ajax 伪代码
      $.ajax({
        url: "服务端",
        data: result,
        dataType: "json",
        success: function (res) {
          console.log(res.result);
        },
      });
    });
  }
);

重置

captchaObj.reset();

后端

后端使用 Nodejs + Express

官方 Demo

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3极验是一款基于Vue3开发的极验验证码组件。它提供了多种验证模式,包括滑块验证码、点选验证码、拼图验证码等,可以轻松地在Vue3项目中使用。以下是使用Vue3极验的步骤: 1. 安装Vue3极验 在Vue3项目中使用npm或yarn安装Vue3极验: ``` npm install @geetest/vue3-geetest --save ``` 2. 引入Vue3极验 在需要使用Vue3极验的组件中,引入并注册Vue3极验组件: ```javascript import { defineComponent } from 'vue' import Geetest from '@geetest/vue3-geetest' export default defineComponent({ name: 'MyComponent', components: { Geetest, }, // ... }) ``` 3. 在模板中使用Vue3极验 在模板中使用`geetest`组件,并传入必要的参数: ```html <template> <div> <Geetest :gt="captcha.gt" :challenge="captcha.challenge" :product="captcha.product" @success="onSuccess" @error="onError" /> </div> </template> ``` 其中,`gt`、`challenge`、`product`是在极验后台获取的参数,`@success`和`@error`是成功和失败的回调函数。具体的参数配置可以参考极验官网提供的文档。 4. 处理回调函数 在组件中定义`onSuccess`和`onError`回调函数: ```javascript export default defineComponent({ name: 'MyComponent', components: { Geetest, }, setup() { const captcha = useCaptcha() const onSuccess = (result) => { console.log(result) // 处理成功逻辑 } const onError = (error) => { console.error(error) // 处理失败逻辑 } return { captcha, onSuccess, onError, } }, // ... }) ``` 在回调函数中可以处理成功和失败的逻辑,例如提交表单、显示提示信息等。 以上就是使用Vue3极验的基本步骤,需要注意的是,在Vue3中使用`ref`来获取DOM元素,而不是像Vue2中一样使用`$refs`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值