xlsdg / react-geetest

A Geetest component for React

Home Page:https://docs.geetest.com/install/deploy/client/web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

那个 reset 方法怎么操作?

rexleimo opened this issue · comments

initGeetest({
    // 省略配置参数
}, function (captchaObj) {
    // 省略其他方法的调用

    // 这里调用了 onSuccess 方法,该方法介绍见下文
    captchaObj.onSuccess(function () {
        var result = captchaObj.getValidate();

        // ajax 伪代码
        ajax('/api/gt-validate', {
            geetest_challenge: result.geetest_challenge,
            geetest_validate: result.geetest_validate,
            geetest_seccode: result.geetest_seccode,

            username: 'xxx',
            password: 'xxx'

            // 其他服务端需要的数据,比如登录时的用户名和密码
        }, function (data) {
            // 根据服务端二次验证的结果进行跳转等操作
            if (data.status === 'fail') {
                alert('用户名或密码错误,请重新输入并完成验证');
                captchaObj.reset(); // 调用该接口进行重置
            }
        });
    });
});

官网地址是这样额

可是我看你的代码里面

  onSuccess: function onSuccess() {},
  onError: function onError() {},
  onClose: function onClose() {},
  ins.appendTo(that.dom);
        ins.onReady(onReady);
        ins.onSuccess(function() {
          return onSuccess(ins.getValidate(), ins);
        });
        ins.onError(onError);
        ins.onClose(onClose);

并没有在onError给我仍和参数

打印一下 onErrorarguments 不就知道了么?参考 https://docs.geetest.com/install/deploy/client/web#onError-callback

@xlsdg 我的问题也是一样,如何重置 验证器。。拿不到 geetest对象撒 http://docs.geetest.com/install/deploy/client/web#reset

@xlsdg 我不是验证失败,可能是用户名输出了之类的。

@rainbowMorelhahahah 你搞定了吗?

稍等,我看一下。

@xgj1988 react-geetest@3.0.2 版本发布了,onReadyonErroronClose 都带了 Geetest 实例参数。

@xlsdg 嗯。。怎么触发onError 呢??我的代码是这样的

  this.props.dispatch({
    type: 'systemLogin/login',
    payload: {
      ...values,
      ...this.geetestSuccessInfo,
      userId: this.userId,
      type
    },
    callback: (data) => {
      if (data.success) {
        LoginUser.login(data);
        this.props.history.push(LoginUser.getWelcomeUrl());
      }
    }
  });

在callback的时候如果success是false 那么就要重置撒

<Geetest
  gt="your-gt"
  challenge="your-challenge"
  onSuccess={onSuccess}
/>

onSuccess 事件的第一个参数可以拿到校验结果,然后请求后端接口判断是否正确。第二个参数是 Geetest 实例,如果错误就调用实例的 reset 方法重置。

@xlsdg 明白了。谢谢