2017 © Pedro Peláez
 

library luocaptcha

Laravel of luosimao captcha

image

lshorz/luocaptcha

Laravel of luosimao captcha

  • Thursday, March 29, 2018
  • by lshorz
  • Repository
  • 1 Watchers
  • 1 Stars
  • 25 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 67 % Grown

The README.md

Luosimao 人机验证 Laravel 5.X 扩展

基于Luosimao免费人机验证的Laravel 5.x扩展, (*1)

介绍, (*2)

安装

$ composer require "lshorz/luocaptcha":"dev-master"

如果是laravel<5.5 则修改config/app.php 增加, (*3)

Lshorz\Luosimao\LCaptchaServiceProvider::class

增加aliases, (*4)

'LCaptcha' => Lshorz\Luosimao\Facades\LCaptcha::class,

配置

1.执行, (*5)

$ php artisan vendor:publish --tag=lcaptcha

2.去官注册帐号并配置config/lcaptcha.php, (*6)

使用方法

在页面head等合适的地方加入, (*7)

<script src="//captcha.luosimao.com/static/js/api.js"></script>

在需要显示该验证组件的地方插入以下代码, (*8)

/**
* @param string $width  组件宽度
* @param string $callback 客户端验证成功回调函数名称
*/
{!! LCaptcha::render('100%', 'callback') !!}

将会生成类似代html代码, (*9)

<div class="l-captcha" data-width="200" data-site-key="xxxxxxxxxxxxxx" data-callback="callback"></div>

另外需要自己补充JS方法,例如将取得的response(默认参数名为:luotest_response)参数post到服务器进行远程验证,参考如下:, (*10)

<script>
    function callback(resp){
        $.post('/check', {"luotest_response": resp}, function(res){
            console.log(res);
        });
    }
</script>

服务端验证

方法一:, (*11)

$v = Validator::make($request->only('luotest_response'), ['luotest_response'=>'required|lcaptcha'], 
 [
    'luotest_response.required' => '不得为空',
    'luotest_response.lcaptcha'=>'验证失败'
 ]);
if ($v->fails()) {
    return $v->errors();
} else {
    return 'ok';
}

方法二:, (*12)

use Lshorz\Luocaptcha\Facades\LCaptcha;

...

$res = LCaptcha::verify($request->only('luotest_response'));
if ($res) {
    echo 'passed';
} else {
    echo 'fail';
}

其他请参考:, (*13)

luosimao官方使用文档

The Versions

29/03 2018

dev-master

9999999-dev

Laravel of luosimao captcha

  Sources   Download

MIT

The Requires

 

by Marven Liao

laravel captcha luosimao

29/03 2018

1.0

1.0.0.0

Laravel of luosimao captcha

  Sources   Download

MIT

The Requires

 

by Marven Liao

laravel captcha luosimao