2017 © Pedro Peláez
 

library captcha-lumen

captcha for lumen

image

yangbx/captcha-lumen

captcha for lumen

  • Thursday, July 12, 2018
  • by Yangbx
  • Repository
  • 1 Watchers
  • 10 Stars
  • 2,017 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 3 Versions
  • 30 % Grown

The README.md

Captcha for Lumen

本項目修改 Captcha for Laravel 5lumen-captcha, (*1)

Requirement

Lumen version >= v5.5, (*2)

Preview

Preview, (*3)

Install

  • 此 Package 必須開啟 Cache 才能使用,因為驗證碼與綁定驗證碼的 uuid 都是保存在 Cache 的。
composer require yangbx/captcha-lumen

How to use

bootstrap/app.php中註冊Captcha Service Provider:, (*4)

    $app->register(Yangbx\CaptchaLumen\CaptchaServiceProvider::class);
    class_alias('Yangbx\CaptchaLumen\Facades\Captcha','Captcha');

Set

bootstrap/app.php中可以設定各種自定義類型的驗證碼屬性,更多詳細設定請查看 Captcha for Laravel 5, (*5)

/**
 * captcha set
 */
config(['captcha'=>
    [
        'useful_time' => 5, //驗證碼有效時間(分鐘)
        'captcha_characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ',
        'sensitive' => false, //驗證碼是否判斷大小寫
        'login'   => [ //驗證碼樣式
            'length'    => 4, //驗證碼字數
            'width'     => 120, //圖片寬度
            'height'    => 36, //字體大小和圖片高度
            'angle'     => 10, //字體傾斜度
            'lines'     => 2, //橫線數
            'quality'   => 90, //品質
            'invert'    =>false, //反相
            'bgImage'   =>true, //背景圖
            'bgColor'   =>'#ffffff',
            'fontColors'=>['#339900','#ff3300','#9966ff','#3333ff'],//字體顏色
        ],
    ]
]);

如果不配置設定檔,默認就是default,驗證碼有效時限為5分鐘。, (*6)

Example

因為 Lumen 都是無狀態的 API,所以驗證碼圖片都會綁上一個 UUID,先獲得驗證碼的 UUID 跟圖片的 URL,驗證時再一併發送驗證碼與 UUID。, (*7)

Generate

獲得驗證碼:, (*8)

{Domain}/captchaInfo/{type?}

type就是在 config 中定義的 Type,如果不指定type,默認為default樣式,Response:, (*9)

{
  "captchaUrl": "http://{Domain}/captcha/default/782fdc90-3406-f2a9-9573-444ea3dc4d5c",
  "captchaUuid": "782fdc90-3406-f2a9-9573-444ea3dc4d5c"
}

captchaUrl為驗證碼圖片的 URL,captchaUuid為綁定驗證碼圖片的uuid。, (*10)

validate

在發送 Request 時將驗證碼與 UUID 一併送回 Server 端,在接收參數時做驗證即可:, (*11)

public function checkCaptcha(Request $request, $type = 'default',$captchaUuid)
{
    $this->validate($request,[
        'captcha'=>'required|captcha:'.$captchaUuid
    ]);
    ...
}

The Versions

12/07 2018

dev-master

9999999-dev

captcha for lumen

  Sources   Download

MIT

The Requires

 

by Avatar Yangbx

captcha lumen captcha captcha for api

12/07 2018

1.0.1

1.0.1.0

captcha for lumen

  Sources   Download

MIT

The Requires

 

by Avatar Yangbx

captcha lumen captcha captcha for api

29/11 2016

1.0.0

1.0.0.0

captcha for lumen

  Sources   Download

MIT

The Requires

 

by Avatar Yangbx

captcha lumen captcha captcha for api