定制 fengbingji/geetest 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fengbingji/geetest

Composer 安装命令:

composer require fengbingji/geetest

包简介

Geetest Package for Laravel8

README 文档

README

Build Status DUB Support Release

Laravel Geetest is a package for Laravel 5-8 developed by Germey. It provides simple usage for laravel of Geetest.

Geetest Demo: Geetest

Installation

Laravel 5.0 or later is required.

This Package now supports Geetest 3.0.

For Geetest 2.0, please see LaravelGeetest 2.0

To get the latest version of Laravel Geetest, simply require the project using Composer:

$ composer require fengbingji/geetest

Or you can add following to require key in composer.json:

"fengbingji/geetest": "~3.0"

then run:

$ composer update

Next, You should need to register the service provider. Open up config/app.php and add following into the providers key:

Germey\Geetest\GeetestServiceProvider::class

And you can register the Geetest Facade in the aliases of config/app.php :

'Geetest' => Germey\Geetest\Geetest::class

Configuration

To get started, you need to publish vendor assets using the following command:

$ php artisan vendor:publish --tag=geetest

This will create a config file named config/geetest.php which you can configure geetest as you like.

It will also generate a views folder named resources/views/vendor/geetest, there will be a view file named geetest.blade.php. Here you can configure styles of geetest. For example, you can change the script alert() as you like.

Usage

Firstly, You need to register in Geetest. Creating an app and get ID and KEY.

For example. You can see app ID and KEY after you added an app in Geetest Admin Page

Then configure them in your .env file because you'd better not make them public.

Add them to .env as follows:

GEETEST_ID=0f1097bef7xxxxxx9afdeced970c63e4
GEETEST_KEY=c070f0628xxxxxxe68e138b55c56fb3b

Then, You can use render() in views like following, It will render a geetest code captcha:

{!! Geetest::render() !!}

For example, you can use it in form like this:

<form action="/" method="post">
    <input name="_token" type="hidden" value="{{ csrf_token() }}">
    <input type="text" name="name" placeholder="name">
    {!! Geetest::render() !!}
    <input type="submit" value="submit">
</form>

It will render like this:

When you click the submit button, it will verify the Geetest Code. If you didn't complete the validation, it will alert some text and prevent the form from submitting.

Or you can set other style of Geetest:

{!! Geetest::render('float') !!}
{!! Geetest::render('bind') !!}
{!! Geetest::render('popup') !!}
{!! Geetest::render('custom') !!}

Then it will be embed or popup style in the website. Default to float.

If the validation is completed, the form will be submitted successfully.

Server Validation

What's the reason that Geetest is safe? If it only has client validation of frontend, can we say it is complete? It also has server validation to ensure that the post request is validate.

First I have to say that you can only use Geetest of Frontend. But you can also do simple things to achieve server validation.

You can use $this->validate() method to achieve server validation. Here is an example:

use Illuminate\Http\Request;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(Request $request)
    {
        $this->validate($request, [
            'geetest_challenge' => 'geetest',
        ], [
            'geetest' => config('geetest.server_fail_alert')
        ]);
        return true;
    }
} 

If we use Geetest, the form will post three extra parameters geetest_challenge geetest_validate geetest_seccode. Geetest use these three parameters to achieve server validation.

If you use ORM, we don't need to add these keys to Model, so you should add following in Model:

protected $guarded = ['geetest_challenge', 'geetest_validate', 'geetest_seccode'];

You can define alert text by altering server_fail_alert in config/geetest.php

Also you can use Request to achieve validation:

<?php namespace App\Http\Requests;
use App\Http\Requests\Request;

class ValidationRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'geetest_challenge' => 'geetest'
        ];
    }

    /**
     * Get validation messages.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'geetest' => 'Validation Failed'
        ];
    }
}

We can use it in our Controller by Request parameter:

use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
use App\Http\Requests\ValidationRequest;

class BaseController extends Controller 
{
    /**
     * @param Request $request
     */
    public function postValidate(ValidationRequest $request)
    {
        // is Validate
    }
} 

Options

Change Ajax Url

If you want to change the Geetest Ajax Url, you can configure it in config/geetest.php, change url as you like, but at this time you need to add extra routes in your routes.php (Laravel 5.2 or former ) or routes/web.php (Laravel 5.3 or later). And you need to add a triat in your controller.

For example, If you add this route:

Route::get('auth/geetest','Auth\AuthController@getGeetest');

you need to add Germey\Geetest\GeetestCaptcha in your AuthController:

use Germey\Geetest\GeetestCaptcha;
class AuthController extends Controller {
    use GeetestCaptcha;
}

Then an Ajax url is configured successfully.

Also you can use this Trait in other Controller but you need to configure url in config/geetest.php.

Configure Url while rendering

Also, you can set Geetest Ajax Url by following way:

{!! Geetest::setGeetestUrl('/auth/geetest')->render() !!}

By setGeetestUrl method you can set Geetest Ajax Url. If it is configured, it will override url configured in config/geetest.php.

Configure Alert Message

You can configure alert message by configure client_fail_alert and server_fail_alert in config/geetest.php.

Configure Language

Geetest supports different language:

  • Simplified Chinese
  • Traditional Chinese
  • English
  • Japanese
  • Korean

You can configure it in config/geetest.php .

Here are key-values of Languge Configuration:

  • zh-cn (Simplified Chinese)
  • zh-tw (Traditional Chinese)
  • en (English)
  • ja (Japanese)
  • ko (Korean)

for example, If you want to use Korean, just change lang key to ko:

'lang' => 'ko'

Configure Protocol

You can configure protocol in config/geetest.php .

for example, If you want to use https, just change protocol key to https:

'protocol' => 'https'

Configure Default Product

You can configure default product in config/geetest.php .

for example, If you want to use popup product, just change product key to popup:

'product' => 'popup'

Mind that it only works when you use like this:

{!! Geetest::render() !!}

If you use like this:

{!! Geetest::render('bind') !!}

It will override the configuration in config/geetest.php.

Contribution

If you find something wrong with this package, you can send an email to cqc@cuiqingcai.com

Or just send a pull request to this repository.

Pull Requests are really welcomed.

Author

Germey , from Beijing China

License

Laravel Geetest is licensed under The MIT License (MIT).

fengbingji/geetest 适用场景与选型建议

fengbingji/geetest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「geetest」 「Germey」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fengbingji/geetest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fengbingji/geetest 我们能提供哪些服务?
定制开发 / 二次开发

基于 fengbingji/geetest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 39
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-04-02