diff --git a/extend/Fastknife/Domain/Factory.php b/extend/Fastknife/Domain/Factory.php deleted file mode 100644 index a95d484b..00000000 --- a/extend/Fastknife/Domain/Factory.php +++ /dev/null @@ -1,161 +0,0 @@ -config = $config; - } - - /** - * @return BlockImage - */ - public function makeBlockImage(): BlockImage - { - $data = new BlockData(); - $image = new BlockImage(); - $this->setCommon($image, $data); - $this->setBlock($image, $data); - return $image; - } - - /** - * @return WordImage - */ - public function makeWordImage(): WordImage - { - $data = new WordData(); - $image = new WordImage(); - $this->setCommon($image, $data); - $this->setWord($image, $data); - return $image; - } - - - /** - * 设置公共配置 - * @param BaseImage $image - * @param BaseData $data - */ - protected function setCommon(BaseImage $image, BaseData $data) - { - //固定驱动,少量图片处理场景gd性能远远大于imagick - ImageManagerStatic::configure(['driver' => 'gd']); - - //获得字体数据 - $fontFile = $data->getFontFile($this->config['font_file']); - $image - ->setFontFile($fontFile) - ->setWatermark($this->config['watermark']); - } - - /** - * 设置滑动验证码的配置 - * @param BlockImage $image - * @param BlockData $data - */ - protected function setBlock(BlockImage $image, BlockData $data) - { - //设置背景 - $backgroundVo = $data->getBackgroundVo($this->config['block_puzzle']['backgrounds']); - $image->setBackgroundVo($backgroundVo); - - $templateVo = $data->getTemplateVo($backgroundVo, $this->config['block_puzzle']['templates']); - - $image->setTemplateVo($templateVo); - - $pixelMaps = [$backgroundVo, $templateVo]; - if ( - isset($this->config['block_puzzle']['is_interfere']) && - $this->config['block_puzzle']['is_interfere'] == true - ) { - $interfereVo = $data->getInterfereVo($backgroundVo, $templateVo, $this->config['block_puzzle']['templates']); - $image->setInterfereVo($interfereVo); - $pixelMaps[] = $interfereVo; - } - - if ( - isset($this->config['block_puzzle']['is_cache_pixel']) && - $this->config['block_puzzle']['is_cache_pixel'] === true - ) { - $cache = $this->getCacheInstance(); - foreach ($pixelMaps as $vo) { - /**@var ImageVo $vo * */ - $key = 'image_pixel_map_' . $vo->src; - $result = $cache->get($key); - if (!empty($result) && is_array($result)) { - $vo->setPickMaps($result); - } else { - $vo->preparePickMaps(); - $vo->setFinishCallback(function (ImageVo $imageVo) use ($cache, $key) { - $cache->set($key, $imageVo->getPickMaps(), 0); - }); - } - } - } - - - } - - /** - * 设置文字验证码的配置 - * @param WordImage $image - * @param WordData $data - */ - protected function setWord(WordImage $image, WordData $data) - { - //设置背景 - $backgroundVo = $data->getBackgroundVo($this->config['click_world']['backgrounds']); - $image->setBackgroundVo($backgroundVo); - - //随机文字坐标 - $pointList = $data->getPointList( - $image->getBackgroundVo()->image->getWidth(), - $image->getBackgroundVo()->image->getHeight(), - 3 - ); - $worldList = $data->getWordList(count($pointList)); - $image - ->setWordList($worldList) - ->setWordList($worldList) - ->setPoint($pointList); - } - - /** - * 创建缓存实体 - */ - public function getCacheInstance(): Cache - { - if (empty($this->cacheInstance)) { - $this->cacheInstance = new Cache($this->config['cache']); - } - return $this->cacheInstance; - } - - public function makeWordData(): WordData - { - return new WordData(); - } - - public function makeBlockData(): BlockData - { - return (new BlockData())->setFaultOffset($this->config['block_puzzle']['offset']); - } -} diff --git a/extend/Fastknife/Domain/Logic/BaseData.php b/extend/Fastknife/Domain/Logic/BaseData.php deleted file mode 100644 index 0cbee61e..00000000 --- a/extend/Fastknife/Domain/Logic/BaseData.php +++ /dev/null @@ -1,73 +0,0 @@ -defaultFontPath; - } - - /** - * 获得随机图片 - * @param $images - * @return string - */ - protected function getRandImage($images): string - { - $index = RandomUtils::getRandomInt(0, count($images) - 1); - return $images[$index]; - } - - /** - * 获取默认图片 - * @param $dir - * @param $images - * @return array|false - */ - protected function getDefaultImage($dir, $images) - { - if (!empty($images)) { - if (is_array($images)) { - return $images; - } - if (is_string($images)) { - $dir = $images; - } - } - return glob($dir . '*.png'); - } - - /** - * 获取一张背景图地址 - * @param null $backgrounds 背景图库 - * @return BackgroundVo - */ - public function getBackgroundVo($backgrounds = null): BackgroundVo - { - $dir = dirname(__DIR__, 3). $this->defaultBackgroundPath; - $backgrounds = $this->getDefaultImage($dir, $backgrounds); - $src = $this->getRandImage($backgrounds); - return new BackgroundVo($src); - } -} diff --git a/extend/Fastknife/Domain/Logic/BaseImage.php b/extend/Fastknife/Domain/Logic/BaseImage.php deleted file mode 100644 index d2058158..00000000 --- a/extend/Fastknife/Domain/Logic/BaseImage.php +++ /dev/null @@ -1,106 +0,0 @@ -point; - } - - /** - * @param $point - * @return WordImage - */ - public function setPoint($point):self - { - $this->point = $point; - return $this; - } - - - protected function makeWatermark(Image $image) - { - if (! empty($this->watermark)) { - $info = imagettfbbox($this->watermark['fontsize'], 0, $this->fontFile, $this->watermark['text']); - $minX = min($info[0], $info[2], $info[4], $info[6]); - $minY = min($info[1], $info[3], $info[5], $info[7]); - $maxY = max($info[1], $info[3], $info[5], $info[7]); - $x = $minX; - $y = abs($minY); - /* 计算文字初始坐标和尺寸 */ - $h = $maxY - $minY; - $x += $image->getWidth() - $this->watermark['fontsize']/2; //留出半个单位字体像素的余白,不至于水印紧贴着右边 - $y += $image->getHeight() - $h; - $image->text($this->watermark['text'], $x, $y, function (Font $font) { - $font->file($this->fontFile); - $font->size($this->watermark['fontsize']); - $font->color($this->watermark['color']); - $font->align('right'); - $font->valign('bottom'); - }); - } - } - - - /** - * @param mixed $watermark - * @return self - */ - public function setWatermark($watermark): self - { - $this->watermark = $watermark; - return $this; - } - - - /** - * @param BackgroundVo $backgroundVo - * @return $this - */ - public function setBackgroundVo(BackgroundVo $backgroundVo):self - { - $this->backgroundVo = $backgroundVo; - return $this; - } - - /** - * @return BackgroundVo - */ - public function getBackgroundVo(): BackgroundVo - { - return $this->backgroundVo; - } - - /** - * @param $file - * @return static - */ - public function setFontFile($file): self - { - $this->fontFile = $file; - return $this; - } - - public abstract function run(); -} diff --git a/extend/Fastknife/Domain/Logic/BlockData.php b/extend/Fastknife/Domain/Logic/BlockData.php deleted file mode 100644 index 89011c89..00000000 --- a/extend/Fastknife/Domain/Logic/BlockData.php +++ /dev/null @@ -1,130 +0,0 @@ -faultOffset; - } - - /** - * @param mixed $faultOffset - */ - public function setFaultOffset($faultOffset): self - { - $this->faultOffset = $faultOffset; - return $this; - } - - - /** - * 获取剪切模板Vo - * @param BackgroundVo $backgroundVo - * @param array $templates - * @return TemplateVo - */ - public function getTemplateVo(BackgroundVo $backgroundVo, array $templates = []): TemplateVo - { - $background = $backgroundVo->image; - //初始偏移量,让模板图在背景的右1/2位置 - $bgWidth = intval($background->getWidth() / 2); - //随机获取一张图片 - $src = $this->getRandImage($this->getTemplateImages($templates)); - - $templateVo = new TemplateVo($src); - - //随机获取偏移量 - $offset = RandomUtils::getRandomInt(0, $bgWidth - $templateVo->image->getWidth() - 1); - - $templateVo->setOffset(new OffsetVo($offset + $bgWidth, 0)); - return $templateVo; - } - - - - public function getInterfereVo(BackgroundVo $backgroundVo, TemplateVo $templateVo, $templates = []): TemplateVo - { - //背景 - $background = $backgroundVo->image; - //模板库去重 - $templates = $this->exclude($this->getTemplateImages($templates), $templateVo->src); - - //随机获取一张模板图 - $src = $this->getRandImage($templates); - - $interfereVo = new TemplateVo($src); - - $maxOffsetX = intval($templateVo->image->getWidth()/2); - do { - //随机获取偏移量 - $offsetX = RandomUtils::getRandomInt(0, $background->getWidth() - $templateVo->image->getWidth() - 1); - - //不与原模板重复 - if ( - abs($templateVo->offset->x - $offsetX) > $maxOffsetX - ) { - $offsetVO = new OffsetVo($offsetX, 0); - $interfereVo->setOffset($offsetVO); - return $interfereVo; - } - } while (true); - } - - - protected function getTemplateImages(array $templates = []) - { - $dir = dirname(__DIR__, 3) . '/resources/defaultImages/jigsaw/slidingBlock/'; - return $this->getDefaultImage($dir, $templates); - } - - /** - * 排除 - * @param $templates - * @param $exclude - * @return array - */ - protected function exclude($templates, $exclude): array - { - if (false !== ($key = array_search($exclude, $templates))) { - array_splice($templates,$key,1); - } - return $templates; - } - - - - /** - * @param $originPoint - * @param $targetPoint - * @return void - */ - public function check($originPoint, $targetPoint) - { - if ( - abs($originPoint->x - $targetPoint->x) <= $this->faultOffset - && $originPoint->y == $targetPoint->y - ) { - return; - } - throw new BlockException('验证失败!'); - } - -} diff --git a/extend/Fastknife/Domain/Logic/BlockImage.php b/extend/Fastknife/Domain/Logic/BlockImage.php deleted file mode 100644 index d990320e..00000000 --- a/extend/Fastknife/Domain/Logic/BlockImage.php +++ /dev/null @@ -1,141 +0,0 @@ -templateVo; - } - - /** - * @param TemplateVo $templateVo - * @return self - */ - public function setTemplateVo(TemplateVo $templateVo): self - { - $this->templateVo = $templateVo; - return $this; - } - - /** - * @return TemplateVo - */ - public function getInterfereVo(): TemplateVo - { - return $this->interfereVo; - } - - /** - * @param TemplateVo $interfereVo - * @return static - */ - public function setInterfereVo(TemplateVo $interfereVo): self - { - - $this->interfereVo = $interfereVo; - return $this; - } - - public function run() - { - $flag = false; - $this->cutByTemplate($this->templateVo, $this->backgroundVo, function ($param) use (&$flag) { - if (!$flag) { - //记录第一个点 - $this->setPoint(new PointVo($param[0], 5));//前端已将y值写死 - $flag = true; - } - }); - if (!empty($this->interfereVo)) { - $this->cutByTemplate($this->interfereVo, $this->backgroundVo); - } - $this->makeWatermark($this->backgroundVo->image); - } - - - public function cutByTemplate(TemplateVo $templateVo, BackgroundVo $backgroundVo, $callable = null) - { - $template = $templateVo->image; - $width = $template->getWidth(); - $height = $template->getHeight(); - for ($x = 0; $x < $width; $x++) { - for ($y = 0; $y < $height; $y++) { - //背景图对应的坐标 - $bgX = $x + $templateVo->offset->x; - $bgY = $y + $templateVo->offset->y; - //是否不透明 - $isOpacity = $templateVo->isOpacity($x, $y); - if ($isOpacity) { //如果不透明 - if ($callable instanceof \Closure) { - $callable([$bgX, $bgY]); - } - $backgroundVo->vagueImage($bgX, $bgY);//模糊背景图选区 - - $this->copyPickColor($backgroundVo, $bgX, $bgY, $templateVo, $x, $y); - } - if ($templateVo->isBoundary($isOpacity, $x, $y)) { - $backgroundVo->setPixel(self::WHITE, $bgX, $bgY); - $templateVo->setPixel(self::WHITE, $x, $y); - } - } - } - } - - /** - * 把$source的颜色复制到$target上 - * @param ImageVo $source - * @param ImageVo $target - */ - - protected function copyPickColor(ImageVo $source, $sourceX, $sourceY, ImageVo $target, $targetX, $targetY) - { - $bgRgba = $source->getPickColor($sourceX, $sourceY); - $target->setPixel($bgRgba, $targetX, $targetY);//复制背景图片给模板 - } - - /** - * 返回前端需要的格式 - * @return false|string[] - */ - public function response($type = 'background') - { - $image = $type == 'background' ? $this->backgroundVo->image : $this->templateVo->image; - $result = $image->encode('data-url')->getEncoded(); - //返回图片base64的第二部分 - return explode(',', $result)[1]; - } - - /** - * 用来调试 - */ - public function echo($type = 'background') - { - $image = $type == 'background' ? $this->backgroundVo->image : $this->templateVo->image; - die($image->response()); - } -} diff --git a/extend/Fastknife/Domain/Logic/Cache.php b/extend/Fastknife/Domain/Logic/Cache.php deleted file mode 100644 index cf35db12..00000000 --- a/extend/Fastknife/Domain/Logic/Cache.php +++ /dev/null @@ -1,114 +0,0 @@ - 'get', - 'set' => 'set', - 'delete' => 'delete', - 'has' => 'has' - ]; - - public function __construct($config) - { - if (isset($config['method'])) { - $this->methodMap = array_merge($this->methodMap, $config['method']); - } - $this->driver = $this->getDriver($config['constructor'], $config['options']??[]); - } - - public function getDriver($callback, $options) - { - if ($callback instanceof \Closure) { - $result = $callback($options); - } else if (is_object($callback)) { - $result = $callback; - } else if (is_array($callback)) { - $result = call_user_func($callback, $options); - } else if ($this->isSerialized($callback)) { - $result = unserialize($callback); - } else if (is_string($callback) && class_exists($callback)) { - $result = new $callback($options); - } else { - $result = new CacheUtils($options); - } - return $result; - } - - /** - * 是否可以被反序列化 - * @param $data - * @return bool - */ - public function isSerialized($data): bool - { - if (!is_string($data)) { - return false; - } - $data = trim($data); - if ('N;' == $data) { - return true; - } - if (!preg_match('/^([adObis]):/', $data, $badions)) { - return false; - } - switch ($badions[1]) { - case 'a' : - case 'O' : - case 's' : - if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data)) - return true; - break; - case 'b' : - case 'i' : - case 'd' : - if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data)) - return true; - break; - } - return false; - } - - public function getDriverMethod($name) - { - return $this->methodMap[$name]; - } - - public function get($key, $default = null) - { - $method = $this->getDriverMethod('get'); - return $this->execute($method, [$key,$default]); - } - - public function set($key, $value, $ttl = null) - { - $method = $this->getDriverMethod('set'); - return $this->execute($method, [$key, $value, $ttl]); - } - - public function delete($key) - { - $method = $this->getDriverMethod('delete'); - return $this->execute($method, [$key]); - } - - public function has($key) - { - $method = $this->getDriverMethod('has'); - return $this->execute($method, [$key]); - } - - protected function execute(string $method, array $params){ - return $this->driver->$method(...$params); - } - -} diff --git a/extend/Fastknife/Domain/Logic/WordData.php b/extend/Fastknife/Domain/Logic/WordData.php deleted file mode 100644 index e4fba23f..00000000 --- a/extend/Fastknife/Domain/Logic/WordData.php +++ /dev/null @@ -1,95 +0,0 @@ -getPoint($width, $height, $i, $number); - } - shuffle($pointList); //随机排序 - return $pointList; - } - - - /** - * @param $list - * @return array - */ - public function array2Point($list): array - { - $result = []; - foreach ($list as $item) { - $result[] = new PointVo($item['x'], $item['y']); - } - return $result; - } - - public function getWordList($number): array - { - return RandomUtils::getRandomChar($number); - } - - /** - * 校验 - * @param array $originPointList - * @param array $targetPointList - */ - public function check(array $originPointList, array $targetPointList) - { - foreach ($originPointList as $key => $originPoint) { - $targetPoint = $targetPointList[$key]; - if ($targetPoint->x - self::FONTSIZE > $originPoint->x - || $targetPoint->x > $originPoint->x + self::FONTSIZE - || $targetPoint->y - self::FONTSIZE > $originPoint->y - || $targetPoint->y > $originPoint->y + self::FONTSIZE) { - throw new WordException('验证失败!'); - } - } - } -} diff --git a/extend/Fastknife/Domain/Logic/WordImage.php b/extend/Fastknife/Domain/Logic/WordImage.php deleted file mode 100644 index 96d600c5..00000000 --- a/extend/Fastknife/Domain/Logic/WordImage.php +++ /dev/null @@ -1,83 +0,0 @@ -wordList = $wordList; - return $this; - } - - public function getWordList() - { - return $this->wordList; - } - - - - public function run() - { - $this->inputWords(); - $this->makeWatermark($this->backgroundVo->image); - } - - /** - * 写入文字 - */ - protected function inputWords(){ - foreach ($this->wordList as $key => $word) { - $point = $this->point[$key]; - $this->backgroundVo->image->text($word, $point->x, $point->y, function (Font $font) { - $font->file($this->fontFile); - $font->size(BaseData::FONTSIZE); - $font->color(RandomUtils::getRandomColor()); - $font->angle(RandomUtils::getRandomAngle()); - $font->align('center'); - $font->valign('center'); - }); - } - } - - /** - * 返回前端需要的格式 - * @return false|string[] - */ - public function response() - { - $result = $this->getBackgroundVo()->image->encode('data-url')->getEncoded(); - //返回图片base64的第二部分 - return explode(',', $result)[1]; - } - - /** - * 用来调试 - */ - public function echo() - { - die($this->getBackgroundVo()->image->response()); - } - -} diff --git a/extend/Fastknife/Domain/Vo/BackgroundVo.php b/extend/Fastknife/Domain/Vo/BackgroundVo.php deleted file mode 100644 index f1dea21a..00000000 --- a/extend/Fastknife/Domain/Vo/BackgroundVo.php +++ /dev/null @@ -1,8 +0,0 @@ -src = $src; - $this->initImage($src); - } - - public function initImage($src) - { - $this->image = ImageManagerStatic::make($src); - } - - /** - * 获取图片中某一个位置的rgba值 - * @param $x - * @param $y - * @return array - */ - public function getPickColor($x, $y): array - { - if (!isset($this->pickMaps[$x][$y])) { - $this->pickMaps[$x][$y] = $this->image->pickColor($x, $y); - } - return $this->pickMaps[$x][$y]; - } - - - /** - * 设置图片指定位置的颜色值 - */ - public function setPixel($color, $x, $y) - { - $this->image->pixel($color, $x, $y); - } - - /** - * @param int $x - * @param int $y - * @return array - */ - public function getBlurValue(int $x, int $y): array - { - $image = $this->image; - $red = []; - $green = []; - $blue = []; - $alpha = []; - foreach ([ - [0, 1], [0, -1], - [1, 0], [-1, 0], - [1, 1], [1, -1], - [-1, 1], [-1, -1], - ] as $distance) //边框取5个点,4个角取3个点,其余取8个点 - { - $pointX = $x + $distance[0]; - $pointY = $y + $distance[1]; - if ($pointX < 0 || $pointX >= $image->getWidth() || $pointY < 0 || $pointY >= $image->height()) { - continue; - } - [$r, $g, $b, $a] = $this->getPickColor($pointX, $pointY); - $red[] = $r; - $green[] = $g; - $blue[] = $b; - $alpha[] = $a; - } - return [MathUtils::avg($red), MathUtils::avg($green), MathUtils::avg($blue), MathUtils::avg($alpha)]; - } - - - /** - * 是否不透明 - * @param $x - * @param $y - * @return bool - */ - public function isOpacity($x, $y): bool - { - return $this->getPickColor($x, $y)[3] > 0.5; - } - - /** - * 是否为边框 - * @param bool $isOpacity - * @param int $x - * @param int $y - * @return bool - */ - public function isBoundary(bool $isOpacity, int $x, int $y): bool - { - $image = $this->image; - if ($x >= $image->width() - 1 || $y >= $image->height() - 1) { - return false; - } - $right = [$x + 1, $y]; - $down = [$x, $y + 1]; - if ( - $isOpacity && !$this->isOpacity(...$right) - || !$isOpacity && $this->isOpacity(...$right) - || $isOpacity && !$this->isOpacity(...$down) - || !$isOpacity && $this->isOpacity(...$down) - ) { - return true; - } - return false; - } - - /** - * 模糊图片 - * @param $targetX - * @param $targetY - */ - public function vagueImage($targetX, $targetY) - { - $blur = $this->getBlurValue($targetX, $targetY); - $this->setPixel($blur, $targetX, $targetY); - } - - - /** - * @return array - */ - public function getPickMaps(): array - { - return $this->pickMaps; - } - - /** - * @param array $pickMaps - */ - public function setPickMaps(array $pickMaps): void - { - $this->pickMaps = $pickMaps; - } - - /** - * 提前初始化像素 - */ - public function preparePickMaps() - { - $width = $this->image->getWidth(); - $height = $this->image->getHeight(); - for ($x = 0; $x < $width; $x++) { - for ($y = 0; $y < $height; $y++) { - $this->getPickColor($x, $y); - } - } - } - - public function setFinishCallback($finishCallback){ - $this->finishCallback = $finishCallback; - } - - public function __destruct() - { - if(!empty($this->finishCallback) && $this->finishCallback instanceof \Closure){ - ($this->finishCallback)($this); - } - } -} \ No newline at end of file diff --git a/extend/Fastknife/Domain/Vo/OffsetVo.php b/extend/Fastknife/Domain/Vo/OffsetVo.php deleted file mode 100644 index 7a6e597f..00000000 --- a/extend/Fastknife/Domain/Vo/OffsetVo.php +++ /dev/null @@ -1,18 +0,0 @@ -x = $x; - $this->y = $y; - } - -} diff --git a/extend/Fastknife/Domain/Vo/PointVo.php b/extend/Fastknife/Domain/Vo/PointVo.php deleted file mode 100644 index 95c63412..00000000 --- a/extend/Fastknife/Domain/Vo/PointVo.php +++ /dev/null @@ -1,22 +0,0 @@ -x = $x; - $this->y = $y; - } -} diff --git a/extend/Fastknife/Domain/Vo/TemplateVo.php b/extend/Fastknife/Domain/Vo/TemplateVo.php deleted file mode 100644 index 8ab7a6eb..00000000 --- a/extend/Fastknife/Domain/Vo/TemplateVo.php +++ /dev/null @@ -1,32 +0,0 @@ -offset; - } - - /** - * @param OffsetVo $offset - */ - public function setOffset(OffsetVo $offset): void - { - $this->offset = $offset; - } - - - -} diff --git a/extend/Fastknife/Exception/BlockException.php b/extend/Fastknife/Exception/BlockException.php deleted file mode 100644 index 2efea377..00000000 --- a/extend/Fastknife/Exception/BlockException.php +++ /dev/null @@ -1,10 +0,0 @@ -factory->getCacheInstance(); - $blockImage = $this->factory->makeBlockImage(); - $blockImage->run(); - $data = [ - 'originalImageBase64' => $blockImage->response(), - 'jigsawImageBase64' => $blockImage->response('template'), - 'secretKey' => RandomUtils::getRandomCode(16, 3), - 'token' => RandomUtils::getUUID(), - ]; - //缓存 - $cacheEntity->set($data['token'], [ - 'secretKey' => $data['secretKey'], - 'point' => $blockImage->getPoint() - ], 7200); - return $data; - } - - - - - /** - * 验证 - * @param string $token - * @param string $pointJson - * @param null $callback - */ - public function validate( $token, $pointJson, $callback = null) - { - //获取并设置 $this->originData - $this->setOriginData($token); - - //数据处理类 - $blockData = $this->factory->makeBlockData(); - - //解码出来的前端坐标 - $targetPoint = $this->encodePoint($this->originData['secretKey'], $pointJson);; - $targetPoint = new PointVo($targetPoint['x'], $targetPoint['y']); - - //检查 - $blockData->check($this->originData['point'], $targetPoint); - if($callback instanceof \Closure){ - $callback(); - } - } -} diff --git a/extend/Fastknife/Service/ClickWordCaptchaService.php b/extend/Fastknife/Service/ClickWordCaptchaService.php deleted file mode 100644 index 8a0483af..00000000 --- a/extend/Fastknife/Service/ClickWordCaptchaService.php +++ /dev/null @@ -1,64 +0,0 @@ -factory->getCacheInstance(); - $wordImage = $this->factory->makeWordImage(); - //执行创建 - $wordImage->run(); - $data = [ - 'originalImageBase64' => $wordImage->response(), - 'secretKey' => RandomUtils::getRandomCode(16, 3), - 'token' => RandomUtils::getUUID(), - 'wordList' => $wordImage->getWordList() - ]; - //缓存 - $cacheEntity->set($data['token'], [ - 'secretKey' => $data['secretKey'], - 'point' => $wordImage->getPoint() - ],7200); - return $data; - } - - - /** - * 验证 - * @param $token - * @param $pointJson - * @param null $callback - */ - public function validate($token, $pointJson, $callback = null) - { - //获取并设置 $this->originData - $this->setOriginData($token); - - //数据实例 - $wordData = $this->factory->makeWordData(); - //解码出来的前端坐标 - $pointJson = $this->encodePoint($this->originData['secretKey'], $pointJson); - $targetPointList = $wordData->array2Point($pointJson); - - //检查 - $wordData->check($this->originData['point'], $targetPointList); - if ($callback instanceof \Closure) { - $callback(); - } - } - - - -} diff --git a/extend/Fastknife/Service/Service.php b/extend/Fastknife/Service/Service.php deleted file mode 100644 index 035e14aa..00000000 --- a/extend/Fastknife/Service/Service.php +++ /dev/null @@ -1,113 +0,0 @@ -factory = new Factory($config); - } - - abstract public function get(); - - - abstract public function validate( $token, $pointJson, $callback = null); - - /** - * 一次验证 - * @param $token - * @param $pointJson - */ - public function check($token, $pointJson) - { - $this->validate($token, $pointJson, function () use ($token, $pointJson) { - $this->setEncryptCache($token, $pointJson); - }); - } - - private function setEncryptCache($token, $pointJson){ - $cacheEntity = $this->factory->getCacheInstance(); - $pointStr = AesUtils::decrypt($pointJson, $this->originData['secretKey']); - $key = AesUtils::encrypt($token. '---'. $pointStr, $this->originData['secretKey']); - $cacheEntity->set($key, - [ - 'token' => $token, - 'point' => $pointJson - ], - 600 - ); - } - - - /** - * 二次验证 - * @param $token - * @param $pointJson - */ - public function verification($token, $pointJson) - { - $this->validate($token, $pointJson, function () use ($token) { - $cacheEntity = $this->factory->getCacheInstance(); - $cacheEntity->delete($token); - }); - } - - /** - * 二次验证,必须要先执行一次验证才能调用二次验证 - * 兼容前端 captchaVerification 传值 - * @param string $encryptCode - */ - public function verificationByEncryptCode(string $encryptCode) - { - $result = $this->factory->getCacheInstance()->get($encryptCode); - if(empty($result)){ - throw new ParamException('参数错误!'); - } - - $this->validate($result['token'], $result['point'], function () use ($result,$encryptCode) { - $cacheEntity = $this->factory->getCacheInstance(); - $cacheEntity->delete($result['token']); - $cacheEntity->delete($encryptCode); - }); - - } - - /** - * 解码坐标点 - * @param $secretKey - * @param $point - * @return array - */ - protected function encodePoint($secretKey, $point): array - { - $pointJson = AesUtils::decrypt($point, $secretKey); - if ($pointJson == false) { - throw new ParamException('aes验签失败!'); - } - return json_decode($pointJson, true); - } - - protected function setOriginData($token){ - $cacheEntity = $this->factory->getCacheInstance(); - $this->originData = $cacheEntity->get($token); - if (empty($this->originData)) { - throw new ParamException('参数校验失败:token'); - } - } -} diff --git a/extend/Fastknife/Utils/AesUtils.php b/extend/Fastknife/Utils/AesUtils.php deleted file mode 100644 index 6c6e193d..00000000 --- a/extend/Fastknife/Utils/AesUtils.php +++ /dev/null @@ -1,39 +0,0 @@ - 300, - 'cache_subdir' => true, - 'prefix' => '', - 'path' => '', - 'hash_type' => 'md5', - 'data_compress' => false, - 'tag_prefix' => 'tag:', - 'serialize' => [], - ]; - - /** - * 缓存读取次数 - * @var integer - */ - protected $readTimes = 0; - - /** - * 缓存写入次数 - * @var integer - */ - protected $writeTimes = 0; - - - /** - * 架构函数 - * @param array $options 参数 - */ - public function __construct(array $options = []) - { - if (!empty($options)) { - $this->options = array_merge($this->options, $options); - } - - if (empty($this->options['path'])) { - $root = isset($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['DOCUMENT_ROOT']) ?$_SERVER['DOCUMENT_ROOT'] : getcwd(); - $this->options['path'] = $root. '/runtime/cache'; - } - - if (substr($this->options['path'], -1) != DIRECTORY_SEPARATOR) { - $this->options['path'] .= DIRECTORY_SEPARATOR; - } - } - - /** - * 取得变量的存储文件名 - * @access public - * @param string $name 缓存变量名 - * @return string - */ - public function getCacheKey(string $name): string - { - $name = hash($this->options['hash_type'], $name); - - if ($this->options['cache_subdir']) { - // 使用子目录 - $name = substr($name, 0, 2) . DIRECTORY_SEPARATOR . substr($name, 2); - } - - if ($this->options['prefix']) { - $name = $this->options['prefix'] . DIRECTORY_SEPARATOR . $name; - } - - return $this->options['path'] . $name . '.php'; - } - - /** - * 获取缓存数据 - * @param string $name 缓存标识名 - * @return array|null - */ - protected function getRaw(string $name) - { - $filename = $this->getCacheKey($name); - - if (!is_file($filename)) { - return; - } - - $content = @file_get_contents($filename); - - if (false !== $content) { - $expire = (int) substr($content, 8, 12); - if (0 != $expire && time() - $expire > filemtime($filename)) { - //缓存过期删除缓存文件 - $this->unlink($filename); - return; - } - - $content = substr($content, 32); - - return is_string($content) ? ['content' => $content, 'expire' => $expire] : null; - } - } - - /** - * 判断缓存是否存在 - * @access public - * @param string $name 缓存变量名 - * @return bool - */ - public function has($name): bool - { - return $this->getRaw($name) !== null; - } - - /** - * 读取缓存 - * @access public - * @param string $name 缓存变量名 - * @param mixed $default 默认值 - * @return mixed - */ - public function get($name, $default = null) - { - $this->readTimes++; - - $raw = $this->getRaw($name); - - return is_null($raw) ? $default : $this->unserialize($raw['content']); - } - - /** - * 写入缓存 - * @access public - * @param string $name 缓存变量名 - * @param mixed $value 存储数据 - * @param int $expire 有效时间 0为永久 - * @return bool - */ - public function set($name, $value, $expire = null): bool - { - $this->writeTimes++; - - if (is_null($expire)) { - $expire = $this->options['expire']; - } - - $filename = $this->getCacheKey($name); - - $dir = dirname($filename); - - if (!is_dir($dir)) { - try { - mkdir($dir, 0755, true); - } catch (\Exception $e) { - // 创建失败 - } - } - - $data = $this->serialize($value); - - if ($this->options['data_compress'] && function_exists('gzcompress')) { - //数据压缩 - $data = gzcompress($data, 3); - } - - $data = "\n" . $data; - $result = file_put_contents($filename, $data); - - if ($result) { - clearstatcache(); - return true; - } - - return false; - } - - /** - * 自增缓存(针对数值缓存) - * @access public - * @param string $name 缓存变量名 - * @param int $step 步长 - * @return false|int - */ - public function inc(string $name, int $step = 1) - { - if ($raw = $this->getRaw($name)) { - $value = $this->unserialize($raw['content']) + $step; - $expire = $raw['expire']; - } else { - $value = $step; - $expire = 0; - } - - return $this->set($name, $value, $expire) ? $value : false; - } - - /** - * 自减缓存(针对数值缓存) - * @access public - * @param string $name 缓存变量名 - * @param int $step 步长 - * @return false|int - */ - public function dec(string $name, int $step = 1) - { - return $this->inc($name, -$step); - } - - /** - * 删除缓存 - * @access public - * @param string $name 缓存变量名 - * @return bool - */ - public function delete($name): bool - { - $this->writeTimes++; - - return $this->unlink($this->getCacheKey($name)); - } - - /** - * 清除缓存 - * @access public - * @return bool - */ - public function clear(): bool - { - $this->writeTimes++; - - $dirname = $this->options['path'] . $this->options['prefix']; - - $this->rmdir($dirname); - - return true; - } - - /** - * 删除缓存标签 - * @access public - * @param array $keys 缓存标识列表 - * @return void - */ - public function clearTag(array $keys): void - { - foreach ($keys as $key) { - $this->unlink($key); - } - } - - /** - * 判断文件是否存在后,删除 - * @access private - * @param string $path - * @return bool - */ - private function unlink(string $path): bool - { - try { - return is_file($path) && unlink($path); - } catch (\Exception $e) { - return false; - } - } - - /** - * 删除文件夹 - * @param $dirname - * @return bool - */ - private function rmdir($dirname) - { - if (!is_dir($dirname)) { - return false; - } - - $items = new \FilesystemIterator($dirname); - - foreach ($items as $item) { - if ($item->isDir() && !$item->isLink()) { - $this->rmdir($item->getPathname()); - } else { - $this->unlink($item->getPathname()); - } - } - - @rmdir($dirname); - - return true; - } - /** - * 序列化数据 - * @access protected - * @param mixed $data 缓存数据 - * @return string - */ - protected function serialize($data): string - { - if (is_numeric($data)) { - return (string) $data; - } - - $serialize = $this->options['serialize'][0] ?? "serialize"; - - return $serialize($data); - } - - /** - * 反序列化数据 - * @access protected - * @param string $data 缓存数据 - * @return mixed - */ - protected function unserialize(string $data) - { - if (is_numeric($data)) { - return $data; - } - - $unserialize = $this->options['serialize'][1] ?? "unserialize"; - - return $unserialize($data); - } - - -} diff --git a/extend/Fastknife/Utils/MathUtils.php b/extend/Fastknife/Utils/MathUtils.php deleted file mode 100644 index aa794730..00000000 --- a/extend/Fastknife/Utils/MathUtils.php +++ /dev/null @@ -1,16 +0,0 @@ - '', //自定义字体包路径, 不填使用默认值 - //文字验证码 - 'click_world' => [ - 'backgrounds' => [] - ], - //滑动验证码 - 'block_puzzle' => [ - /*背景图片路径, 不填使用默认值, 支持string与array两种数据结构。string为默认图片的目录,array索引数组则为具体图片的地址*/ - 'backgrounds' => [], - - /*模板图,格式同上支持string与array*/ - 'templates' => [], - - 'offset' => 10, //容错偏移量 - - 'is_cache_pixel' => true, //是否开启缓存图片像素值,开启后能提升服务端响应性能(但要注意更换图片时,需要清除缓存) - - 'is_interfere' => true, //开启干扰图 - ], - //水印 - 'watermark' => [ - 'fontsize' => 12, - 'color' => '#000000', - 'text' => '我的水印' - ], - 'cache' => [ - //若您使用了框架,并且想使用类似于redis这样的缓存驱动,则应换成框架的中的缓存驱动 - 'constructor' => \Fastknife\Utils\CacheUtils::class, - 'method' => [ - //遵守PSR-16规范不需要设置此项(tp6, laravel,hyperf)。如tp5就不支持(tp5缓存方法是rm,所以要配置为"delete" => "rm") - /** - 'get' => 'get', //获取 - 'set' => 'set', //设置 - 'delete' => 'delete',//删除 - 'has' => 'has' //key是否存在 - */ - ], - 'options' => [ - //如果您依然使用\Fastknife\Utils\CacheUtils做为您的缓存驱动,那么您可以自定义缓存配置。 - 'expire' => 300,//缓存有效期 (默认为0 表示永久缓存) - 'prefix' => '', //缓存前缀 - 'path' => '', //缓存目录 - 'serialize' => [], //缓存序列化和反序列化方法 - ] - ] -]; diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/1.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/1.png deleted file mode 100644 index 022aabf9..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/1.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/2.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/2.png deleted file mode 100644 index 914908e8..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/2.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/3.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/3.png deleted file mode 100644 index f0f3ce58..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/3.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/4.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/4.png deleted file mode 100644 index c5697f3c..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/4.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/5.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/5.png deleted file mode 100644 index e29e7a3c..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/5.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/6.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/6.png deleted file mode 100644 index 2425f412..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/6.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/original/bg8.png b/extend/Fastknife/resources/defaultImages/jigsaw/original/bg8.png deleted file mode 100644 index 5ea54d48..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/original/bg8.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/1.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/1.png deleted file mode 100644 index 19050266..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/1.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/2.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/2.png deleted file mode 100644 index b1482d48..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/2.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/3.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/3.png deleted file mode 100644 index cdbb0b18..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/3.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/4.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/4.png deleted file mode 100644 index bc69c962..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/4.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/5.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/5.png deleted file mode 100644 index 0080a546..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/5.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/6.png b/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/6.png deleted file mode 100644 index b07c3b40..00000000 Binary files a/extend/Fastknife/resources/defaultImages/jigsaw/slidingBlock/6.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/1.png b/extend/Fastknife/resources/defaultImages/pic-click/1.png deleted file mode 100644 index 50dfe28e..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/1.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/2.png b/extend/Fastknife/resources/defaultImages/pic-click/2.png deleted file mode 100644 index 15b38ad2..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/2.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/3.png b/extend/Fastknife/resources/defaultImages/pic-click/3.png deleted file mode 100644 index e2e487bd..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/3.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/4.png b/extend/Fastknife/resources/defaultImages/pic-click/4.png deleted file mode 100644 index c34baa40..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/4.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/5.png b/extend/Fastknife/resources/defaultImages/pic-click/5.png deleted file mode 100644 index 0b3d11a2..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/5.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/6.png b/extend/Fastknife/resources/defaultImages/pic-click/6.png deleted file mode 100644 index 67797a11..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/6.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg10.png b/extend/Fastknife/resources/defaultImages/pic-click/bg10.png deleted file mode 100644 index c99fbcb0..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg10.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg11.png b/extend/Fastknife/resources/defaultImages/pic-click/bg11.png deleted file mode 100644 index 6a951d32..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg11.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg12.png b/extend/Fastknife/resources/defaultImages/pic-click/bg12.png deleted file mode 100644 index a38ada50..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg12.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg13.png b/extend/Fastknife/resources/defaultImages/pic-click/bg13.png deleted file mode 100644 index 07af86a8..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg13.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg14.png b/extend/Fastknife/resources/defaultImages/pic-click/bg14.png deleted file mode 100644 index 95593759..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg14.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg15.png b/extend/Fastknife/resources/defaultImages/pic-click/bg15.png deleted file mode 100644 index cb1ebb63..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg15.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg16.png b/extend/Fastknife/resources/defaultImages/pic-click/bg16.png deleted file mode 100644 index 106b4562..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg16.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg17.png b/extend/Fastknife/resources/defaultImages/pic-click/bg17.png deleted file mode 100644 index bcdbe765..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg17.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg18.png b/extend/Fastknife/resources/defaultImages/pic-click/bg18.png deleted file mode 100644 index ae94e09c..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg18.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg19.png b/extend/Fastknife/resources/defaultImages/pic-click/bg19.png deleted file mode 100644 index bef9318b..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg19.png and /dev/null differ diff --git a/extend/Fastknife/resources/defaultImages/pic-click/bg20.png b/extend/Fastknife/resources/defaultImages/pic-click/bg20.png deleted file mode 100644 index 36cfbdec..00000000 Binary files a/extend/Fastknife/resources/defaultImages/pic-click/bg20.png and /dev/null differ diff --git a/extend/Fastknife/resources/fonts/WenQuanZhengHei.ttf b/extend/Fastknife/resources/fonts/WenQuanZhengHei.ttf deleted file mode 100644 index f84e9feb..00000000 Binary files a/extend/Fastknife/resources/fonts/WenQuanZhengHei.ttf and /dev/null differ diff --git a/extend/Fastknife/resources/fonts/license.txt b/extend/Fastknife/resources/fonts/license.txt deleted file mode 100644 index 719f68f0..00000000 --- a/extend/Fastknife/resources/fonts/license.txt +++ /dev/null @@ -1,55 +0,0 @@ -文泉驿是一个开源汉字字体项目 - -由旅美学者房骞骞(FangQ) - -于2004年10月创建 - -集中力量解决GNU/Linux - -高质量中文字体匮乏的状况 - -目前,文泉驿已经开发并发布了 - -第一个完整覆盖GB18030汉字 - -(包含27000多个汉字) - -的多规格点阵汉字字型文件 - -第一个覆盖GBK字符集的 - -开源矢量字型文件(文泉驿正黑) - -并提供了目前包含字符数目最多的 - -开源字体——GNU Unifont——中 - -绝大多数中日韩文相关的符号 - -这些字型文件已经逐渐成为 - -主流Linux/Unix发行版 - -中文桌面的首选中文字体 - -目前Ubuntu、Fedora、Slackware - -Magic Linux、CDLinux - -使用文泉驿作为默认中文字体 - -Debian、Gentoo、Mandriva - -ArchLinux、Frugalware - -则提供了官方源支持 - -而FreeBSD则在其ports中有提供 - -所以,今天我们所要分享的就是 - -文泉驿正黑体 - -可在Linux/UNIX,Windows - -Mac OS和嵌入式操作系统中使用 \ No newline at end of file