ranshaodeguodong

     资源见下网址

1.下载项目中的zip(版本1.0)

2.在dos界面安装:composer require laravist/geecaptcha

3.在.env文件中添加geetest(一个验证码验证提供商)的ID和KEY

CAPTCHA_ID=你自己的(要注册)
PRIVATE_KEY=你自己的

4.(1)在路由中实例化:$captcha = new \Laravist\GeeCaptcha\GeeCaptcha($captcha_id, $private_key);

   (2)判断验证码是否验证成功

if ($captcha->isFromGTServer()) {

   if ($captcha->success()) {

      return \'登录成功\';

   }

   return \'登录失败\';

   }

   (3)对于需要重新生成验证码时(一般放在get方式的路由里):

$captcha = new \Laravist\GeeCaptcha\GeeCaptcha($captcha_id, $private_key);

echo $captcha->GTServerIsNormal();

   (4)login视图:

<!DOCTYPE html>
<html>
    <head>
        <title>Laravel Geetest</title>
        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
        <script src="http://api.geetest.com/get.php"></script>
    </head>
    <body>
        <div class="container">
            <div class="content" id="container">
                <div class="title">Laravel 5</div>
                <form method="post" action="/verify">
                    {{ csrf_field() }}
                    <div class="box">
                        <label>邮箱:</label>
                        <input type="text" name="email" value=""/>
                    </div>
                    <div class="box">
                        <label>密码:</label>
                        <input type="password" name="password" />
                    </div>
                    <div class="box" id="div_geetest_lib">
                        <div id="captcha"></div>
                        <script src="http://static.geetest.com/static/tools/gt.js"></script>
                        <script>
                            var handler = function (captchaObj) {
                                // 将验证码加到id为captcha的元素里
                                captchaObj.appendTo("#captcha");
                            };
                            $.ajax({
                                // 获取id,challenge,success(是否启用failback)
                                url: "captcha?rand="+Math.round(Math.random()*100),
                                type: "get",
                                dataType: "json", // 使用jsonp格式
                                success: function (data) {
                                    // 使用initGeetest接口
                                    // 参数1:配置参数,与创建Geetest实例时接受的参数一致
                                    // 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
                                    initGeetest({
                                        gt: data.gt,
                                        challenge: data.challenge,
                                        product: "float", // 产品形式
                                        offline: !data.success
                                    }, handler);
                                }
                            });
                        </script>
                    </div>
                    <div class="box">
                        <button id="submit_button">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </body>
</html>

另附一张路由图片供参考:

有视频资源网址:https://www.codecasts.com/series/tools-that-are-dame-good-for-developer/episodes/1
视频中项目网址:https://github.com/JellyBool/geeCaptcha(非官方)
geetest服务商网站(需注册):https://account.geetest.com/base/report/total




分类:

技术点:

相关文章:

  • 2021-06-05
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2021-07-14
  • 2021-06-27
  • 2021-07-15
  • 2022-01-03
猜你喜欢
  • 2021-08-17
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案