-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from evalor/master
验证码类功能更新
- Loading branch information
Showing
4 changed files
with
241 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
}, | ||
"autoload": { | ||
"psr-4": { | ||
"easySwoole\\":"src" | ||
"easySwoole\\VerifyCode\\":"src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ class Conf extends SplBean | |
public $useNoise = false; // 随机噪点 | ||
public $useFont = null; // 指定字体 | ||
public $fontColor = null; // 字体颜色 | ||
public $backColor = null; // 背景颜色 | ||
public $imageL = null; // 图片宽度 | ||
public $imageH = null; // 图片高度 | ||
public $fonts = []; // 额外字体 | ||
|
@@ -35,13 +36,173 @@ protected function initialize() | |
{ | ||
} | ||
|
||
public function __set($name, $value) | ||
/** | ||
* 设置字符集 | ||
* @param string $charset | ||
* @return Conf | ||
*/ | ||
public function setCharset($charset) | ||
{ | ||
$this->$name = $value; | ||
is_string($charset) && $this->charset = $charset; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 开启混淆曲线 | ||
* @param bool $useCurve | ||
* @return Conf | ||
*/ | ||
public function setUseCurve($useCurve = true) | ||
{ | ||
is_bool($useCurve) && $this->useCurve = $useCurve; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 开启噪点生成 | ||
* @param bool $useNoise | ||
* @return Conf | ||
*/ | ||
public function setUseNoise($useNoise = true) | ||
{ | ||
is_bool($useNoise) && $this->useNoise = $useNoise; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 使用自定义字体 | ||
* @param string $useFont | ||
* @return Conf | ||
*/ | ||
public function setUseFont($useFont) | ||
{ | ||
is_string($useFont) && $this->useFont = $useFont; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置文字颜色 | ||
* @param array|string $fontColor | ||
* @return Conf | ||
*/ | ||
public function setFontColor($fontColor) | ||
{ | ||
if (is_string($fontColor)) $this->fontColor = $this->HEXToRGB($fontColor); | ||
if (is_array($fontColor)) $this->fontColor = $fontColor; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置背景颜色 | ||
* @param null $backColor | ||
* @return Conf | ||
*/ | ||
public function setBackColor($backColor) | ||
{ | ||
if (is_string($backColor)) $this->backColor = $this->HEXToRGB($backColor); | ||
if (is_array($backColor)) $this->backColor = $backColor; | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置图片宽度 | ||
* @param int|string $imageL | ||
* @return Conf | ||
*/ | ||
public function setImageWidth($imageL) | ||
{ | ||
$this->imageL = intval($imageL); | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置图片高度 | ||
* @param null $imageH | ||
* @return Conf | ||
*/ | ||
public function setImageHeight($imageH) | ||
{ | ||
$this->imageH = intval($imageH); | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置字体集 | ||
* @param array|string $fonts | ||
* @return Conf | ||
*/ | ||
public function setFonts($fonts) | ||
{ | ||
if (is_string($fonts)) array_push($this->fonts, $fonts); | ||
if (is_array($fonts) && !empty($fonts)) { | ||
if (empty($this->fonts)) { | ||
$this->fonts = $fonts; | ||
} else { | ||
array_merge($this->fonts, $fonts); | ||
} | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置字体尺寸 | ||
* @param int $fontSize | ||
* @return Conf | ||
*/ | ||
public function setFontSize($fontSize) | ||
{ | ||
$this->fontSize = intval($fontSize); | ||
return $this; | ||
} | ||
|
||
/** | ||
* 设置验证码长度 | ||
* @param int $length | ||
* @return Conf | ||
*/ | ||
public function setLength($length) | ||
{ | ||
$this->length = intval($length); | ||
return $this; | ||
} | ||
|
||
/** | ||
* 获取配置值 | ||
* @param $name | ||
* @author : evalor <[email protected]> | ||
* @return mixed | ||
*/ | ||
public function __get($name) | ||
{ | ||
return $this->$name; | ||
} | ||
|
||
/** | ||
* 十六进制转RGB | ||
* @param $hexColor | ||
* @author : evalor <[email protected]> | ||
* @return array | ||
*/ | ||
function HEXToRGB($hexColor) | ||
{ | ||
$color = str_replace('#', '', $hexColor); | ||
if (strlen($color) > 3) { | ||
$rgb = array( | ||
hexdec(substr($color, 0, 2)), | ||
hexdec(substr($color, 2, 2)), | ||
hexdec(substr($color, 4, 2)) | ||
); | ||
} else { | ||
$color = $hexColor; | ||
$r = substr($color, 0, 1) . substr($color, 0, 1); | ||
$g = substr($color, 1, 1) . substr($color, 1, 1); | ||
$b = substr($color, 2, 1) . substr($color, 2, 1); | ||
$rgb = array( | ||
hexdec($r), | ||
hexdec($g), | ||
hexdec($b) | ||
); | ||
} | ||
return $rgb; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters