验证码
namespace ginkgo;
class Captcha {
// 属性
public $chars = 'abdefhijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
public $secKey = 'ginkgo';
public $config = array();
protected static $instance;
private $configThis = array(
'length' => 4,
'expire' => 1800,
'font_file' => '',
'font_size' => 20,
'width' => 0,
'height' => 0,
'reset' => true,
'noise' => true,
'shadow' => array(1, 2),
);
private $res_img;
// 已弃用属性
public $offset = array(1, 2);
// 方法
public static instance( [ array $config ] ) : object
public create( [ string $id ] ) : object
public check( [ string $id ] ) : bool
protected __construct( [ array $config ] ) : object
protected __clone()
private createCode()
private createBg()
private createFont()
private createNoise()
private output() : object
private authcode( string $str ) : string
private fontProcess() : string
// 已弃用方法
public set( [ int $font_size = 20 [, int $length = 4 ]] )
}
- | 权限 | 类型 | 描述 |
---|---|---|---|
属性 | - | - | - |
$chars |
public | string | 字符池 |
$secKey |
public | string | 安全码 |
$config |
public | array | 配置 |
$instance |
protected | object static | 本类的实例 |
$configThis |
private | array | 默认配置 |
$captcha |
private | string | 验证码 |
$res_img |
private | resource | 图形资源 |
已弃用属性 | - | - | - |
$offset |
public | array | 阴影偏移(0.2.0 起弃用) |
方法 | - | - | - |
instance() | public | static | 实例化方法 |
config() | public | 配置(0.2.0 新增) |
|
create() | public | 对外生成 | |
check() | public | 验证 | |
__construct() | protected | 同 instance() | |
__clone() | protected | 克隆,无实际功能,仅供限制为单例模式使用 | |
createCode() | private | 生成验证码 | |
createBg() | private | 生成图片及背景 | |
createFont() | private | 生成文字 | |
createNoise() | private | 加入干扰 | |
output() | private | 输出 | |
authcode() | private | 加密 | |
fontProcess() | private | 随机取得字体文件路径 | |
已弃用方法 | - | - | - |
set() | public | 设置(0.2.0 起弃用) |
$config
配置,$configThis
默认配置public $config;
private $configThis;
结构
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
length | int | 4 | 验证码长度 |
expire | int | 1800 | 过期时间 |
font_file | string | 字体文件的路径 | |
font_size | int | 20 | 字号 |
width | int | 0 | 图片宽度 |
height | int | 0 | 图片高度 |
reset | bool | true | 验证成功后是否重置 |
noise | bool | true | 是否加入干扰 |
shadow | array | array(1, 2) | 阴影偏移(0.2.0 新增) |
$offset
阴影偏移0.2.0
起弃用
public $offset = array(1, 2);
结构
名称 | 类型 | 默认 | 描述 |
---|---|---|---|
0 | int | 1 | X 轴偏移量(像素) |
1 | int | 2 | Y 轴偏移量(像素) |
instance()
实例化public static function instance( [ array $config ] ) : object
参数
config
配置参数返回
set()
设置0.2.0
起弃用
public function set( [ int $font_size = 20 [, int $length = 4 ]] )
参数
font_size
字号length
验证码长度返回
config()
配置0.2.0
新增
public function config( array $config )
参数
config
配置参数返回
create()
对外生成public function create( [ string $id ] ) : object
参数
id
验证码 ID,一般用于多个验证码返回
check()
验证public function check( [ string $id ] ) : bool
参数
id
验证码 ID,一般用于多个验证码返回
createCode()
生成验证码private function createCode()
参数
返回
createBg()
生成图片及背景private function createBg()
参数
返回
createFont()
生成文字private function createFont()
参数
返回
createNoise()
加入干扰private function createNoise()
参数
返回
output()
输出private function output() : object
参数
返回
authcode()
加密private function authcode( string $str ) : string
参数
str
字符串返回
fontProcess()
随机取得字体文件路径private function fontProcess() : string
参数
返回