{"id":16329710,"url":"https://github.com/germey/laravelgeetest","last_synced_at":"2025-04-05T22:09:15.782Z","repository":{"id":62510180,"uuid":"64112189","full_name":"Germey/LaravelGeetest","owner":"Germey","description":"Geetest Package for Laravel5","archived":false,"fork":false,"pushed_at":"2020-07-05T18:12:26.000Z","size":77,"stargazers_count":157,"open_issues_count":5,"forks_count":40,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-06-25T13:27:54.976Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/germey/geetest","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Germey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-25T07:14:20.000Z","updated_at":"2024-03-07T02:10:33.000Z","dependencies_parsed_at":"2022-11-02T13:01:13.251Z","dependency_job_id":null,"html_url":"https://github.com/Germey/LaravelGeetest","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Germey%2FLaravelGeetest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Germey%2FLaravelGeetest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Germey%2FLaravelGeetest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Germey%2FLaravelGeetest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Germey","download_url":"https://codeload.github.com/Germey/LaravelGeetest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406091,"owners_count":20933803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T23:16:54.029Z","updated_at":"2025-04-05T22:09:15.752Z","avatar_url":"https://github.com/Germey.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Geetest\n\n[![Build Status](https://travis-ci.org/Germey/LaravelGeetest.svg?branch=master)](https://travis-ci.org/Germey/LaravelGeetest)\n[![DUB](https://img.shields.io/dub/l/vibe-d.svg?maxAge=2592000?style=plastic)](https://github.com/Germey/LaravelGeetest)\n[![Support](https://img.shields.io/badge/support-laravel-orange.svg)](https://laravel.com/)\n[![Release](https://img.shields.io/badge/release-3.0.0-orange.svg)](https://github.com/Germey/LaravelGeetest/releases)\n\nLaravel Geetest is a package for Laravel 5 developed by [Germey](http://cuiqingcai.com). It provides simple usage for laravel of [Geetest](http://www.geetest.com/). \n\nGeetest Demo: [Geetest](https://www.geetest.com/show)\n\n## Installation\n\nLaravel 5.0 or later is required.\n\nThis Package now supports Geetest 3.0. \n\nFor Geetest 2.0, please see [LaravelGeetest 2.0](https://github.com/Germey/LaravelGeetest/tree/v2.0.3)\n\nTo get the latest version of Laravel Geetest, simply require the project using Composer:\n\n```\n$ composer require germey/geetest\n```\n\nOr you can add following to `require` key in `composer.json`:\n\n```json\n\"germey/geetest\": \"~3.0\"\n```\n\nthen run:\n\n```\n$ composer update\n```\n\nNext, You should need to register the service provider. Open up `config/app.php` and add following into the `providers` key:\n\n```php\nGermey\\Geetest\\GeetestServiceProvider::class\n```\n\nAnd you can register the Geetest Facade in the `aliases` of `config/app.php` :\n\n```php\n'Geetest' =\u003e Germey\\Geetest\\Geetest::class\n```\n\n## Configuration\n\nTo get started, you need to publish vendor assets using the following command:\n\n```\n$ php artisan vendor:publish --tag=geetest\n```\n\nThis will create a config file named `config/geetest.php` which you can configure geetest as you like.\n\nIt 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.\n\n## Usage\n\nFirstly, You need to register in [Geetest](http://www.geetest.com/). Creating an app and get `ID` and `KEY`.\n\nFor example. You can see app `ID` and `KEY` after you added an app in [Geetest Admin Page](http://account.geetest.com)\n\n![](https://ws3.sinaimg.cn/large/006tKfTcly1fh3qherw91j31kw0e6q4p.jpg)\n\nThen configure them in your `.env` file because you'd better not make them public.\n\nAdd them to `.env` as follows:\n\n```\nGEETEST_ID=0f1097bef7xxxxxx9afdeced970c63e4\nGEETEST_KEY=c070f0628xxxxxxe68e138b55c56fb3b\n```\n\nThen, You can use `render()` in views like following, It will render a geetest code captcha:\n\n```php\n{!! Geetest::render() !!}\n```\n\n For example, you can use it in `form` like this:\n\n```html\n\u003cform action=\"/\" method=\"post\"\u003e\n    \u003cinput name=\"_token\" type=\"hidden\" value=\"{{ csrf_token() }}\"\u003e\n    \u003cinput type=\"text\" name=\"name\" placeholder=\"name\"\u003e\n    {!! Geetest::render() !!}\n    \u003cinput type=\"submit\" value=\"submit\"\u003e\n\u003c/form\u003e\n```\n\nIt will render like this:\n\n![](https://ws4.sinaimg.cn/large/006tKfTcly1fh3qp3fhafj30i8052q37.jpg)\n\n\nWhen 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.\n\nOr you can set other style of Geetest:\n\n```php\n{!! Geetest::render('float') !!}\n{!! Geetest::render('bind') !!}\n{!! Geetest::render('popup') !!}\n{!! Geetest::render('custom') !!}\n```\n\nThen it will be embed or popup style in the website. Default to `float`.\n\nIf the validation is completed, the form will be submitted successfully.\n\n## Server Validation\n\nWhat'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.\n\nFirst I have to say that you can only use Geetest of Frontend. But you can also do simple things to achieve server validation.\n\nYou can use `$this-\u003evalidate()` method to achieve server validation. Here is an example:\n\n```php\nuse Illuminate\\Http\\Request;\n\nclass BaseController extends Controller \n{\n    /**\n     * @param Request $request\n     */\n    public function postValidate(Request $request)\n    {\n        $this-\u003evalidate($request, [\n            'geetest_challenge' =\u003e 'geetest',\n        ], [\n            'geetest' =\u003e config('geetest.server_fail_alert')\n        ]);\n        return true;\n    }\n} \n```\n\nIf 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.\n\nIf you use ORM, we don't need to add these keys to Model, so you should add following in Model:\n\n```php\nprotected $guarded = ['geetest_challenge', 'geetest_validate', 'geetest_seccode'];\n```\n\nYou can define alert text by altering `server_fail_alert` in `config/geetest.php`\n\nAlso you can use Request to achieve validation:\n\n```php\n\u003c?php namespace App\\Http\\Requests;\nuse App\\Http\\Requests\\Request;\n\nclass ValidationRequest extends Request\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @return array\n     */\n    public function rules()\n    {\n        return [\n            'geetest_challenge' =\u003e 'geetest'\n        ];\n    }\n\n    /**\n     * Get validation messages.\n     *\n     * @return array\n     */\n    public function messages()\n    {\n        return [\n            'geetest' =\u003e 'Validation Failed'\n        ];\n    }\n}\n\n```\n\nWe can use it in our Controller by Request parameter:\n\n```php\nuse Illuminate\\Support\\Facades\\Config;\nuse Illuminate\\Http\\Request;\nuse App\\Http\\Requests\\ValidationRequest;\n\nclass BaseController extends Controller \n{\n    /**\n     * @param Request $request\n     */\n    public function postValidate(ValidationRequest $request)\n    {\n        // is Validate\n    }\n} \n```\n\n## Options\n\n### Change Ajax Url\n\nIf 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.\n\nFor example, If you add this route:\n\n```php\nRoute::get('auth/geetest','Auth\\AuthController@getGeetest');\n```\n\nyou need to add  `Germey\\Geetest\\GeetestCaptcha` in your `AuthController`:\n\n```php\nuse Germey\\Geetest\\GeetestCaptcha;\nclass AuthController extends Controller {\n    use GeetestCaptcha;\n}\n```\n\nThen an Ajax url is configured successfully.\n\nAlso you can use this Trait in other Controller but you need to configure  `url` in `config/geetest.php`.\n\n### Configure Url while rendering\n\nAlso, you can set Geetest Ajax Url by following way:\n\n```php\n{!! Geetest::setGeetestUrl('/auth/geetest')-\u003erender() !!}\n```\n\nBy `setGeetestUrl` method you can set Geetest Ajax Url. If it is configured, it will override `url` configured in `config/geetest.php`.\n\n### Configure Alert Message\n\nYou can configure alert message by configure `client_fail_alert` and `server_fail_alert` in `config/geetest.php`.\n\n### Configure Language\n\nGeetest supports different language:\n\n* Simplified Chinese\n* Traditional Chinese\n* English\n* Japanese\n* Korean\n\nYou can configure it in `config/geetest.php` .\n\nHere are key-values of Languge Configuration:\n\n- zh-cn (Simplified Chinese) \n- zh-tw (Traditional Chinese)\n- en (English)\n- ja (Japanese)\n- ko (Korean)\n\nfor example, If you want to use Korean, just change `lang` key to `ko`:\n\n```php\n'lang' =\u003e 'ko'\n```\n\n### Configure Protocol\n\nYou can configure protocol in `config/geetest.php` .\n\nfor example, If you want to use https, just change `protocol` key to `https`:\n\n```php\n'protocol' =\u003e 'https'\n```\n\n### Configure Default Product\n\nYou can configure default product in `config/geetest.php` .\n\nfor example, If you want to use popup product, just change `product` key to `popup`:\n\n```php\n'product' =\u003e 'popup'\n```\n\nMind that it only works when you use like this:\n\n```php\n{!! Geetest::render() !!}\n```\n\nIf you use like this:\n\n```php\n{!! Geetest::render('bind') !!}\n```\n\nIt will override the configuration in `config/geetest.php`.\n\n## Contribution\n\nIf you find something wrong with this package, you can send an email to `cqc@cuiqingcai.com`\n\nOr just send a pull request to this repository. \n\nPull Requests are really welcomed.\n\n## Author\n\n[Germey](http://cuiqingcai.com) , from Beijing China\n\n## License\n\nLaravel Geetest is licensed under [The MIT License (MIT)](https://github.com/Germey/LaravelGeetest/blob/master/LICENSE).\n\n\n\n \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgermey%2Flaravelgeetest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgermey%2Flaravelgeetest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgermey%2Flaravelgeetest/lists"}