dyjh 7 年 前
コミット
f7a44f6629
4 ファイル変更145 行追加0 行削除
  1. 1 0
      composer.json
  2. 3 0
      config/app.php
  3. 91 0
      config/geetest.php
  4. 50 0
      resources/views/vendor/geetest/geetest.blade.php

+ 1 - 0
composer.json

xqd
@@ -10,6 +10,7 @@
         "doctrine/dbal": "^2.5",
         "dsiddharth2/php-zxing": "^1.0",
         "fideloper/proxy": "~3.3",
+        "germey/geetest": "^3.0",
         "intervention/image": "^2.4",
         "johnlui/aliyun-oss": "2.2",
         "kosinix/grafika": "dev-master",

+ 3 - 0
config/app.php

xqd xqd xqd
@@ -140,6 +140,7 @@ return [
         /*
            * Laravel Framework Service Providers...
            */
+        Germey\Geetest\GeetestServiceProvider::class,
         Illuminate\Auth\AuthServiceProvider::class,
         Illuminate\Broadcasting\BroadcastServiceProvider::class,
         Illuminate\Bus\BusServiceProvider::class,
@@ -182,6 +183,7 @@ return [
         Maatwebsite\Excel\ExcelServiceProvider::class,
         Dingo\Api\Provider\LaravelServiceProvider::class,
         Overtrue\LaravelWeChat\ServiceProvider::class,
+
     ],
 
     /*
@@ -233,6 +235,7 @@ return [
         'Image' => Intervention\Image\Facades\Image::class,
         'Excel' => Maatwebsite\Excel\Facades\Excel::class,
         'EasyWeChat' => Overtrue\LaravelWeChat\Facade::class,
+        'Geetest' => Germey\Geetest\Geetest::class,
     ],
 
 ];

+ 91 - 0
config/geetest.php

xqd
@@ -0,0 +1,91 @@
+<?php
+return [
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Language
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your yunpian api key from yunpian provided.
+    |
+    | Options: ['zh-cn', 'zh-tw', 'en', 'ja', 'ko']
+    |
+    */
+    'lang' => 'zh-cn',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Geetest Id
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your yunpian api key from yunpian provided.
+    |
+    */
+    'id' => 'b46d1900d0a894591916ea94ea91bd2c',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Geetest Key
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your yunpian api key from yunpian provided.
+    |
+    */
+    'key' => '36fc3fe98530eea08dfc6ce76e3d24c4',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Geetest URL
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your geetest url for ajax validation.
+    |
+    */
+    'url' => '/geetest',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Geetest Protocol
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your geetest url for ajax validation.
+    |
+    | Options: http or https
+    |
+    */
+    'protocol' => 'http',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Geetest Product
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config your geetest url for ajax validation.
+    |
+    | Options: float, popup, custom, bind
+    |
+    */
+    'product' => 'float',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Client Fail Alert Text
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config the alert text when it failed in client.
+    |
+    */
+    'client_fail_alert' => '请正确完成验证码操作',
+
+    /*
+    |--------------------------------------------------------------------------
+    | Config Server Fail Alert
+    |--------------------------------------------------------------------------
+    |
+    | Here you can config the alert text when it failed in server (two factor validation).
+    |
+    */
+    'server_fail_alert' => '验证码校验失败',
+
+
+];

+ 50 - 0
resources/views/vendor/geetest/geetest.blade.php

xqd
@@ -0,0 +1,50 @@
+<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script>
+<script src="https://static.geetest.com/static/tools/gt.js"></script>
+<div id="{{ $captchaid }}"></div>
+<p id="wait-{{ $captchaid }}" class="show">正在加载验证码...</p>
+@define use Illuminate\Support\Facades\Config
+<script>
+    var geetest = function(url) {
+        var handlerEmbed = function(captchaObj) {
+            $("#{{ $captchaid }}").closest('form').submit(function(e) {
+                var validate = captchaObj.getValidate();
+                if (!validate) {
+                    alert('{{ Config::get('geetest.client_fail_alert')}}');
+                    e.preventDefault();
+                }
+            });
+            captchaObj.appendTo("#{{ $captchaid }}");
+            captchaObj.onReady(function() {
+                $("#wait-{{ $captchaid }}")[0].className = "hide";
+            });
+            if ('{{ $product }}' == 'popup') {
+                captchaObj.bindOn($('#{{ $captchaid }}').closest('form').find(':submit'));
+                captchaObj.appendTo("#{{ $captchaid }}");
+            }
+        };
+        $.ajax({
+            url: url + "?t=" + (new Date()).getTime(),
+            type: "get",
+            dataType: "json",
+            success: function(data) {
+                initGeetest({
+                    gt: data.gt,
+                    challenge: data.challenge,
+                    product: "{{ $product?$product:Config::get('geetest.product', 'float') }}",
+                    offline: !data.success,
+                    new_captcha: data.new_captcha,
+                    lang: '{{ Config::get('geetest.lang', 'zh-cn') }}',
+                    http: '{{ Config::get('geetest.protocol', 'http') }}' + '://'
+                }, handlerEmbed);
+            }
+        });
+    };
+    (function() {
+        geetest('{{ $url?$url:Config::get('geetest.url', 'geetest') }}');
+    })();
+</script>
+<style>
+    .hide {
+        display: none;
+    }
+</style>