SOURCE

console 命令行工具 X clear

                    
>
console
var handlerEmbed = function(captchaObj) {
  $("#embed-submit").click(function(e) {
    var validate = captchaObj.getValidate();
    if (!validate) {
      $("#notice")[0].className = "show";
      setTimeout(function() {
        $("#notice")[0].className = "hide";
      },
      2000);
      e.preventDefault();
    }
  });
  // 将验证码加到id为captcha的元素里
  captchaObj.appendTo("#embed-captcha");
  captchaObj.onReady(function() {
    $("#wait")[0].className = "hide";
  });
};
$.ajax({
  // 获取id,challenge,success(是否启用failback)
  url: "{:U('Jiyan/StartCaptchaServlet')}?t=" + (new Date()).getTime(),
  // 加随机数防止缓存
  type: "get",
  dataType: "json",
  success: function(data) {
    // 使用initGeetest接口
    // 参数1:配置参数
    // 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
    initGeetest({
      gt: data.gt,
      challenge: data.challenge,
      product: "embed",
      // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
      offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
    },
    handlerEmbed);
  }
});
<php> namespace Api\Controller; use Think\Controller; class JiyanController
extends Controller { /* 这里id和key是测试的 在用户管理后台,有这两个参数,只要填上去即可。 */ private
$id; private $key; private $GtSdk; public function _initialize() { $this->
  id = "b46d1900d0a894591916ea94ea91bd2c"; $this->key = "36fc3fe98530eea08dfc6ce76e3d24c4";
  $this->GtSdk = new \Org\Util\GeetestLib($this->id, $this->key); } public
  function index() { $this->display(); } /** * 使用Get的方式返回:challenge和capthca_id
  此方式以实现前后端完全分离的开发模式 专门实现failback * @author Tanxu */ //error_reporting(0);
  public function StartCaptchaServlet() { session_start(); $user_id = "test";
  $status = $this->GtSdk->pre_process($user_id); $_SESSION['gtserver'] =
  $status; $_SESSION['user_id'] = $user_id; echo $this->GtSdk->get_response_str();
  } /** * 输出二次验证结果,本文件示例只是简单的输出 Yes or No */ // error_reporting(0); public
  function VerifyLoginServlet() { $user_id = $_SESSION['user_id']; if ($_SESSION['gtserver']
  == 1) { $result = $this->GtSdk->success_validate($_POST['geetest_challenge'],
  $_POST['geetest_validate'], $_POST['geetest_seccode'], $user_id); if ($result)
  { echo 'Yes!'; } else{ echo 'No'; } }else{ if ($this->GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode']))
  { echo "yes"; }else{ echo "no"; } } } } </php>
  <form class="popup" action="" method="post">
    <h2>
      嵌入式Demo,使用表单形式提交二次验证所需的验证结果值
    </h2>
    <br>
    <p>
      <label for="user">
        用户名:
      </label>
      <input class="inp" id="user" type="text" value="极验验证">
    </p>
    <br>
    <p>
      <label for="password">
        密&nbsp;&nbsp;&nbsp;&nbsp;码:
      </label>
      <input class="inp" id="password" type="password" value="123456">
    </p>
    <div id="embed-captcha">
    </div>
    <p id="wait" class="show">
      正在加载验证码......
    </p>
    <p id="notice" class="hide">
      请先拖动验证码到相应位置
    </p>
    <br>
    <input class="btn" id="embed-submit" type="submit" value="提交">
  </form>

本项目引用的自定义外部资源