deschamps-jeremy/php-captcha

简单的问答式验证码生成器

1.0.2 2021-03-20 17:06 UTC

This package is auto-updated.

Last update: 2024-09-21 01:06:47 UTC


README

Jeremy Deschamps编写

简单的问答式验证码生成器

贡献者

  • 在CLI中下载仓库
git clone https://github.com/DeschampsJeremy/PhpCaptcha.git

staging分支上推送。

安装

  • 在CLI中下载仓库
composer require deschamps-jeremy/php-captcha
  • 导入
use DeschampsJeremy\CaptchaService;

方法

static get(): array

从列表中获取验证码并返回一个数组,格式为 ['token' => int, 'base64' => string]。此代码将创建一个唯一的token响应

var_dump([
    0 => CaptchaService::get(),
    1 => CaptchaService::get(),
]);

array(2) {
    [0]=> array(2) {
        ["token"]=> string(28) "20201011111830_5f7ec344d119e"
        ["base64"]=> //A JPG image on base64 string
    },
    [1]=> array(2) {
        ["token"]=> string(28) "20201011111830_5f7ec344d2580"
        ["base64"]=> //A JPG image on base64 string
    }
}

static isValid(string $token, string $response): bool

检查验证码是否有效

var_dump([
    0 => CaptchaService::isValid("20201011111830_5f7ec344d119e", "good response"),
    1 => CaptchaService::isValid("20201011111830_5f7ec344d119e", "good response"),
    2 => CaptchaService::isValid("20201011111830_5f7ec344d2580", "bad response"),
]);

array(2) {
    [0]=> bool(true)
    [1]=> bool(false)
    [2]=> bool(false)
}