From 13b89fcf79926b5c28080d8cca0bfc537befebbf Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Sat, 12 Dec 2015 01:01:23 +0800 Subject: [PATCH 01/12] Update config.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持在外部定义配置文件。 --- config/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.php b/config/config.php index 0f57fe2..6910f22 100644 --- a/config/config.php +++ b/config/config.php @@ -3,7 +3,7 @@ * Geetest配置文件 * @author Tanxu */ -define("CAPTCHA_ID", "3386e03c620a4067f18fa92c370f1594"); -define("PRIVATE_KEY", "5fe89444b54d3a3b8e49594c42a770cf"); +defined('CAPTCHA_ID') or define('CAPTCHA_ID', '3386e03c620a4067f18fa92c370f1594'); +defined('PRIVATE_KEY') or define('PRIVATE_KEY', '5fe89444b54d3a3b8e49594c42a770cf'); - ?> \ No newline at end of file + ?> From 08578a12af316218a12a19c6568f3cd50ca0ce7a Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 11:37:54 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E6=8C=81compo?= =?UTF-8?q?ser=E3=80=82=20=E5=A2=9E=E5=8A=A0Laravel=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 9 ++++- config/config.php | 12 +++--- lib/class.geetestlib.php | 25 +++++++----- msg/StartMsgCaptchaServlet.php | 6 +-- msg/VerifyGeetestServlet.php | 8 ++-- msg/VerifyMsgServlet.php | 4 +- src/Laravel/Facades/Geetest.php | 18 +++++++++ src/Laravel/Geetest.php | 26 ++++++++++++ src/Laravel/GeetestServiceProvider.php | 56 ++++++++++++++++++++++++++ src/Laravel/GeetestValidator.php | 20 +++++++++ web/StartCaptchaServlet.php | 8 ++-- 11 files changed, 162 insertions(+), 30 deletions(-) create mode 100644 src/Laravel/Facades/Geetest.php create mode 100644 src/Laravel/Geetest.php create mode 100644 src/Laravel/GeetestServiceProvider.php create mode 100644 src/Laravel/GeetestValidator.php diff --git a/composer.json b/composer.json index 1c7b41c..3a88e27 100644 --- a/composer.json +++ b/composer.json @@ -10,10 +10,17 @@ "require": { "php": ">=5.0.0" }, + "require-dev": { + "illuminate/support": "5.*", + "illuminate/validation": "5.*" + }, "autoload": { "classmap": [ "lib" - ] + ], + "psr-4": { + "GeeTeam\\Geetest\\": "src/" + } }, "license": "MIT" } \ No newline at end of file diff --git a/config/config.php b/config/config.php index 6910f22..3d0af23 100644 --- a/config/config.php +++ b/config/config.php @@ -1,9 +1,11 @@ - +// defined('CAPTCHA_ID') or define('CAPTCHA_ID', '3386e03c620a4067f18fa92c370f1594'); +// defined('PRIVATE_KEY') or define('PRIVATE_KEY', '5fe89444b54d3a3b8e49594c42a770cf'); +return [ + 'captcha_id' => '3386e03c620a4067f18fa92c370f1594', + 'private_key' => '5fe89444b54d3a3b8e49594c42a770cf' +]; diff --git a/lib/class.geetestlib.php b/lib/class.geetestlib.php index 0949d2a..4e2100b 100755 --- a/lib/class.geetestlib.php +++ b/lib/class.geetestlib.php @@ -3,10 +3,13 @@ * 极验行为式验证安全平台,php 网站主后台包含的库文件 *@author Tanxu */ -require_once dirname(dirname(__FILE__)) . '/config/config.php'; +// require_once dirname(dirname(__FILE__)) . '/config/config.php'; class GeetestLib{ const GT_SDK_VERSION = 'php_2.15.7.6.1'; public function __construct() { + $config = include __DIR__ . '/../config/config.php'; + $this->captcha_id = $config['captcha_id']; + $this->private_key = $config['private_key']; $this->challenge = ""; } @@ -16,7 +19,7 @@ public function __construct() { * @return */ public function register() { - $url = "http://api.geetest.com/register.php?gt=" . CAPTCHA_ID; + $url = "http://api.geetest.com/register.php?gt=" . $this->captcha_id; $this->challenge = $this->send_request($url); if (strlen($this->challenge) != 32) { return 0; @@ -45,7 +48,7 @@ private function check_validate($challenge, $validate) { if (strlen($validate) != 32) { return FALSE; } - if (md5(PRIVATE_KEY.'geetest'.$challenge) != $validate) { + if (md5($this->private_key.'geetest'.$challenge) != $validate) { return FALSE; } return TRUE; @@ -63,7 +66,7 @@ private function send_request($url){ 'http'=>array( 'method'=>"GET", 'timeout'=>2, - ) + ) ); $context = stream_context_create($opts); $data = file_get_contents($url, false, $context); @@ -89,7 +92,7 @@ private function decode_response($challenge,$string) { $res = 0; $array_challenge = str_split($challenge); $array_value = str_split($string); - for ($i=0; $i < strlen($challenge); $i++) { + for ($i=0; $i < strlen($challenge); $i++) { $item = $array_challenge[$i]; if (in_array($item, $chongfu)) { continue; @@ -101,11 +104,11 @@ private function decode_response($challenge,$string) { } } - for ($j=0; $j < strlen($string); $j++) { + for ($j=0; $j < strlen($string); $j++) { $res += $key[$array_value[$j]]; } $res = $res - $this->decodeRandBase($challenge); - return $res; + return $res; } @@ -138,7 +141,7 @@ private function get_failback_pic_ans($full_bg_index,$img_grp_index) { $answer_decode = ""; // 通过两个字符串奇数和偶数位拼接产生答案位 - for ($i=0; $i < 9; $i++) { + for ($i=0; $i < 9; $i++) { if ($i % 2 == 0) { $answer_decode = $answer_decode . $full_bg_name[$i]; }elseif ($i % 2 == 1) { @@ -152,14 +155,14 @@ private function get_failback_pic_ans($full_bg_index,$img_grp_index) { /** * 输入的两位的随机数字,解码出偏移量 - * + * * @param challenge * @return */ private function decodeRandBase($challenge) { $base = substr($challenge, 32, 2); $tempArray = array(); - for ($i=0; $i < strlen($base); $i++) { + for ($i=0; $i < strlen($base); $i++) { $tempAscii = ord($base[$i]); $result = ($tempAscii > 57) ? ($tempAscii - 87) : ($tempAscii -48); array_push($tempArray,$result); @@ -170,7 +173,7 @@ private function decodeRandBase($challenge) { /** * 得到答案 - * + * * @param validate * @return */ diff --git a/msg/StartMsgCaptchaServlet.php b/msg/StartMsgCaptchaServlet.php index e845594..19d3cf3 100644 --- a/msg/StartMsgCaptchaServlet.php +++ b/msg/StartMsgCaptchaServlet.php @@ -1,4 +1,4 @@ - 1, - 'gt' => CAPTCHA_ID, + 'gt' => $GtMsgSdk->captcha_id, 'challenge' => $GtMsgSdk->challenge ); echo json_encode($result); @@ -24,6 +24,6 @@ ); echo json_encode($result); } - + ?> \ No newline at end of file diff --git a/msg/VerifyGeetestServlet.php b/msg/VerifyGeetestServlet.php index 334c5f1..2e8e517 100644 --- a/msg/VerifyGeetestServlet.php +++ b/msg/VerifyGeetestServlet.php @@ -1,20 +1,20 @@ -private_key . 'geetest' . $data['geetest_challenge'])) { $codedata = array( "seccode" => $data['geetest_seccode'], "sdk" => "php_2.15.4.1.1", "phone" =>$data['phone'], - "msg_id" => CAPTCHA_ID + "msg_id" => $GtMsgSdk->captcha_id ); $action = "send"; $result = $GtMsgSdk->send_msg_request($action,$codedata); diff --git a/msg/VerifyMsgServlet.php b/msg/VerifyMsgServlet.php index 69f5bc4..392e85f 100644 --- a/msg/VerifyMsgServlet.php +++ b/msg/VerifyMsgServlet.php @@ -1,4 +1,4 @@ - $phone, - 'msg_id' => CAPTCHA_ID, + 'msg_id' => $GtMsgSdk->captcha_id, 'code' => $code ); $result = $GtMsgSdk->send_msg_request($action,$data); diff --git a/src/Laravel/Facades/Geetest.php b/src/Laravel/Facades/Geetest.php new file mode 100644 index 0000000..c5200e5 --- /dev/null +++ b/src/Laravel/Facades/Geetest.php @@ -0,0 +1,18 @@ + $this->captcha_id, + 'challenge' => $this->challenge, + 'product' => $product + ); + if ($product == "popup") { + $params["popupbtnid"] = $popupbtnid; + } + return ''; + } +} diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php new file mode 100644 index 0000000..e22fa83 --- /dev/null +++ b/src/Laravel/GeetestServiceProvider.php @@ -0,0 +1,56 @@ +app->singleton('geetest', function ($app) { + require_once base_path('vendor/gee-team/gt-php-sdk/src/class.geetest.php'); + $config = $app->config->get('geetest'); + $geetest = new \Geetest(); + $geetest->set_captchaid($config['captcha_id']); + $geetest->set_privatekey($config['private_key']); + return $geetest; + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + 'geetest' + ]; + } +} diff --git a/src/Laravel/GeetestValidator.php b/src/Laravel/GeetestValidator.php new file mode 100644 index 0000000..0694f8f --- /dev/null +++ b/src/Laravel/GeetestValidator.php @@ -0,0 +1,20 @@ +data) && key_exists('geetest_validate', $this->data) && key_exists('geetest_seccode', $this->data)) { + return true === app('geetest')->validate($this->data['geetest_challenge'], $this->data['geetest_validate'], $this->data['geetest_seccode']); + } + return false; + } +} \ No newline at end of file diff --git a/web/StartCaptchaServlet.php b/web/StartCaptchaServlet.php index 890eea3..41862a8 100644 --- a/web/StartCaptchaServlet.php +++ b/web/StartCaptchaServlet.php @@ -1,4 +1,4 @@ - 1, - 'gt' => CAPTCHA_ID, + 'gt' => $GtSdk->captcha_id, 'challenge' => $GtSdk->challenge ); echo json_encode($result); @@ -23,12 +23,12 @@ $challenge = $rnd1 . substr($rnd2,0,2); $result = array( 'success' => 0, - 'gt' => CAPTCHA_ID, + 'gt' => $GtSdk->captcha_id, 'challenge' => $challenge ); $_SESSION['challenge'] = $result['challenge']; echo json_encode($result); } - + ?> \ No newline at end of file From 5387fe7c7eb4bf2c33d2cf7cc93952f17a64419e Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 11:43:42 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E5=BC=95=E7=94=A8=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/GeetestServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php index e22fa83..2696233 100644 --- a/src/Laravel/GeetestServiceProvider.php +++ b/src/Laravel/GeetestServiceProvider.php @@ -2,7 +2,7 @@ namespace GeeTeam\Geetest; use Illuminate\Support\ServiceProvider; -use Illuminate\Validation\Validator; +use Illuminate\Support\Facades\Validator; /** * 极验行为式验证 From de6526640c2565e8ee4b6bf1ccb1f0282713dad9 Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 11:50:24 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=8F=AF=E4=BB=A5=E5=9C=A8=E7=B1=BB=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/class.geetestlib.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/class.geetestlib.php b/lib/class.geetestlib.php index 4e2100b..9c7886c 100755 --- a/lib/class.geetestlib.php +++ b/lib/class.geetestlib.php @@ -7,10 +7,15 @@ class GeetestLib{ const GT_SDK_VERSION = 'php_2.15.7.6.1'; public function __construct() { + $this->challenge = ""; + $config = include __DIR__ . '/../config/config.php'; + $this->setConfig($config); + } + + public function setConfig($config){ $this->captcha_id = $config['captcha_id']; $this->private_key = $config['private_key']; - $this->challenge = ""; } /** From 600c5fbae62c8ca87e6510e7f8a26802ee0bef1a Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 11:50:59 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E6=96=B9=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/GeetestServiceProvider.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php index 2696233..47cf32e 100644 --- a/src/Laravel/GeetestServiceProvider.php +++ b/src/Laravel/GeetestServiceProvider.php @@ -33,11 +33,9 @@ public function boot() public function register() { $this->app->singleton('geetest', function ($app) { - require_once base_path('vendor/gee-team/gt-php-sdk/src/class.geetest.php'); $config = $app->config->get('geetest'); - $geetest = new \Geetest(); - $geetest->set_captchaid($config['captcha_id']); - $geetest->set_privatekey($config['private_key']); + $geetest = new Geetest(); + $geetest->setConfig($config); return $geetest; }); } From f231b2a0c23d69c443b36729f5605929fc980cbe Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 11:52:23 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/Facades/Geetest.php | 2 +- src/Laravel/Geetest.php | 2 +- src/Laravel/GeetestServiceProvider.php | 2 +- src/Laravel/GeetestValidator.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Laravel/Facades/Geetest.php b/src/Laravel/Facades/Geetest.php index c5200e5..df45c5d 100644 --- a/src/Laravel/Facades/Geetest.php +++ b/src/Laravel/Facades/Geetest.php @@ -1,5 +1,5 @@ Date: Tue, 12 Jan 2016 11:54:38 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E7=B1=BB=E5=BC=95=E7=94=A8=E5=9C=B0=E5=9D=80=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/Geetest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Laravel/Geetest.php b/src/Laravel/Geetest.php index b534120..62948f1 100644 --- a/src/Laravel/Geetest.php +++ b/src/Laravel/Geetest.php @@ -8,7 +8,7 @@ * * @author Latrell Chan */ -class Geetest extends GeetestLib +class Geetest extends \GeetestLib { public function get_widget($product, $popupbtnid = "") From b9e42155b9fa046f7f36f8a142e7c45c42c9f298 Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 12:31:13 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/Geetest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Laravel/Geetest.php b/src/Laravel/Geetest.php index 62948f1..db0f3e9 100644 --- a/src/Laravel/Geetest.php +++ b/src/Laravel/Geetest.php @@ -11,7 +11,7 @@ class Geetest extends \GeetestLib { - public function get_widget($product, $popupbtnid = "") + public function getWidget($product, $popupbtnid = '') { $params = array( 'gt' => $this->captcha_id, From fa36effcb7d3613d61cd9d0d4add9c7d00ba6a0b Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 14:05:03 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8B=E7=BB=8D?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++ src/Laravel/readme.md | 68 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 src/Laravel/readme.md diff --git a/README.md b/README.md index e64f24d..6ae2316 100755 --- a/README.md +++ b/README.md @@ -50,6 +50,10 @@ GtWeb Php Demo! - 获取短信前的一次验证逻辑控制 - ./VerifyMsgServlet.php - 提交短信验证示例Servlet +6. src/ + - ./Laravel/* + - Laravel 框架扩展包 + 发布日志(由新到旧) ====================== diff --git a/src/Laravel/readme.md b/src/Laravel/readme.md new file mode 100755 index 0000000..22818e0 --- /dev/null +++ b/src/Laravel/readme.md @@ -0,0 +1,68 @@ +gt-php-sdk +============ + +极验行为式验证 for Laravel 扩展包。 + +## 使用 + +要使用本服务提供者,你必须自己注册服务提供者到Laravel服务提供者列表中。 + +打开配置文件 `config/app.php`。 + +找到key为 `providers` 的数组,在数组中添加服务提供者。 + +```php + 'providers' => [ + // ... + GeeTeam\Geetest\Laravel\GeetestServiceProvider::class, + ] +``` + +找到key为 `aliases` 的数组,在数组中注册Facades。 + +```php + 'aliases' => [ + // ... + 'Geetest' => GeeTeam\Geetest\Laravel\Facades\Geetest::class, + ] +``` + +运行 `php artisan vendor:publish` 命令,发布配置文件到你的项目中。 + +修改配置文件 `config/geetest.php` 内的配置信息。 + +## 例子 + +### 视图 login.blade.php +``` + ... + @if (Geetest::register()) + {!! Geetest::getWidget('float')!!} + @else + + 图形验证码 + @endif + ... +``` + +### 控制器 AuthController.php +```php + // 验证输入。 + $validator = $this->getValidationFactory()->make($request->all(), [ + // ... + ], [ + 'captcha.required' => '请填写验证图片中的文字。', + 'geetest_challenge.required' => '请拖动滑块完成验证。' + ]); + $validator->sometimes('captcha', 'required|captcha', function ($input) { + // 其它验证方式,比如图形验证码。 + return is_null($input->geetest_challenge) || is_null($input->geetest_validate) || is_null($input->geetest_seccode); + }); + $validator->sometimes('geetest_challenge', 'required|geetest', function ($input) { + // 极验行为式验证。 + return ! is_null($input->geetest_challenge) && ! is_null($input->geetest_validate) && ! is_null($input->geetest_seccode); + }); + if ($validator->fails()) { + $this->throwValidationException($request, $validator); + } +``` From fd65b38bdfa2b37c507ef75bc7d86200f57593c0 Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 14:07:48 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Laravel=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8F=91=E5=B8=83=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/GeetestServiceProvider.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php index b795e28..2e8d7b2 100644 --- a/src/Laravel/GeetestServiceProvider.php +++ b/src/Laravel/GeetestServiceProvider.php @@ -19,6 +19,10 @@ class GeetestServiceProvider extends ServiceProvider */ public function boot() { + $this->publishes([ + __DIR__ . '/../../config/config.php' => config_path('geetest.php') + ]); + // 注册自定义验证器扩展。 Validator::resolver(function ($translator, $data, $rules, $messages) { return new GeetestValidator($translator, $data, $rules, $messages); @@ -32,6 +36,8 @@ public function boot() */ public function register() { + $this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'geetest'); + $this->app->singleton('geetest', function ($app) { $config = $app->config->get('geetest'); $geetest = new Geetest(); From 155cad8b2d10a9c94c1836ea1f0249e90f8f4288 Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Tue, 12 Jan 2016 15:59:44 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=99=A8=E6=89=A9=E5=B1=95=E6=B3=A8=E5=86=8C=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/GeetestServiceProvider.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php index 2e8d7b2..7d6b589 100644 --- a/src/Laravel/GeetestServiceProvider.php +++ b/src/Laravel/GeetestServiceProvider.php @@ -23,10 +23,8 @@ public function boot() __DIR__ . '/../../config/config.php' => config_path('geetest.php') ]); - // 注册自定义验证器扩展。 - Validator::resolver(function ($translator, $data, $rules, $messages) { - return new GeetestValidator($translator, $data, $rules, $messages); - }); + // 注册验证器扩展。 + Validator::extend('geetest', 'GeetestValidator@validateGeetest'); } /** From 06f0d32c8566a7de92cbfd930305af8395c840c5 Mon Sep 17 00:00:00 2001 From: Latrell Chan Date: Wed, 13 Jan 2016 11:44:46 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=99=A8=E6=89=A9=E5=B1=95=E7=9A=84=E6=B3=A8=E5=86=8C=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Laravel/GeetestServiceProvider.php | 3 +-- src/Laravel/GeetestValidator.php | 20 -------------------- src/Laravel/validation.php | 9 +++++++++ 3 files changed, 10 insertions(+), 22 deletions(-) delete mode 100644 src/Laravel/GeetestValidator.php create mode 100644 src/Laravel/validation.php diff --git a/src/Laravel/GeetestServiceProvider.php b/src/Laravel/GeetestServiceProvider.php index 7d6b589..2df9727 100644 --- a/src/Laravel/GeetestServiceProvider.php +++ b/src/Laravel/GeetestServiceProvider.php @@ -2,7 +2,6 @@ namespace GeeTeam\Geetest\Laravel; use Illuminate\Support\ServiceProvider; -use Illuminate\Support\Facades\Validator; /** * 极验行为式验证 @@ -24,7 +23,7 @@ public function boot() ]); // 注册验证器扩展。 - Validator::extend('geetest', 'GeetestValidator@validateGeetest'); + require __DIR__ . '/validation.php'; } /** diff --git a/src/Laravel/GeetestValidator.php b/src/Laravel/GeetestValidator.php deleted file mode 100644 index 5ec7f0b..0000000 --- a/src/Laravel/GeetestValidator.php +++ /dev/null @@ -1,20 +0,0 @@ -data) && key_exists('geetest_validate', $this->data) && key_exists('geetest_seccode', $this->data)) { - return true === app('geetest')->validate($this->data['geetest_challenge'], $this->data['geetest_validate'], $this->data['geetest_seccode']); - } - return false; - } -} \ No newline at end of file diff --git a/src/Laravel/validation.php b/src/Laravel/validation.php new file mode 100644 index 0000000..f39cd59 --- /dev/null +++ b/src/Laravel/validation.php @@ -0,0 +1,9 @@ +getData(); + if (key_exists('geetest_challenge', $data) && key_exists('geetest_validate', $data) && key_exists('geetest_seccode', $data)) { + return true === app('geetest')->validate($data['geetest_challenge'], $data['geetest_validate'], $data['geetest_seccode']); + } + return false; +});