junliuxian/lumen-geetest

geetest sense bot for lumen 5+

3.0 2018-04-25 15:35 UTC

This package is not auto-updated.

Last update: 2024-11-10 05:56:38 UTC


README

极验验证码,Lumen 框架简洁实现

安装

  • 使用 composer 快速安装

    composer require junliuxian/geetest

  • bootstrap/app.php 文件中添加这一行。注意,你还需要开启 Session

    $app->register(Junliuxian\Geetest\GeetestServiceProvider::class);

  • 启用 session 服务,在 bootstrap/app.php 中添加以下代码

       $app->configure('session');
       $app->alias('session', Illuminate\Session\SessionManager::class); 
       
       $app->middleware([
           Illuminate\Session\Middleware\StartSession::class,
       ]);
       
       $app->register(Illuminate\Session\SessionServiceProvider::class);
    

使用

  • .env 文件中添加配置

    GEETEST_ID=
    GEETEST_KEY=
    
  • 在控制器中引用 Geetest

    namespace App\Http\Controllers;
    
    use Laravel\Lumen\Routing\Controller;
    use Junliuxian\Geetest\Traits\Geetest;
    
    class LoginController extends Controller
    {
        use Geetest;
    }
    
  • routes\web.php 文件中添加路由

    $router->post('captcha', 'LoginController@getGeetest');
    
  • 客户端部署,参考 geetest

  • 二次验证

    ```
    namespace App\Http\Controllers;
    
    use Laravel\Lumen\Routing\Controller;
    use Junliuxian\Geetest\Traits\Geetest;
    
    class LoginController extends Controller
    {
        use Geetest;
        
        public function login(Request $request)
        {
            $this->validate($request, [
                 // 注意,验证的字段必须是 challenge
                'geetest_challenge' => 'geetest'
            ]);
        }
    }
    ```