new files
This commit is contained in:
106
pro_v3.5.1/vendor/fastknife/ajcaptcha/test/laravel/IndexController.php
vendored
Normal file
106
pro_v3.5.1/vendor/fastknife/ajcaptcha/test/laravel/IndexController.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Fastknife\Exception\ParamException;
|
||||
use Fastknife\Service\BlockPuzzleCaptchaService;
|
||||
use Fastknife\Service\ClickWordCaptchaService;
|
||||
use Fastknife\Service\Service;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class IndexController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$service = $this->getCaptchaService();
|
||||
$data = $service->get();
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一次验证
|
||||
* @return array
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
try {
|
||||
$data = $this->validate();
|
||||
$service = $this->getCaptchaService();
|
||||
$service->check($data['token'], $data['pointJson']);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二次验证
|
||||
* @return array
|
||||
*/
|
||||
public function verification()
|
||||
{
|
||||
try {
|
||||
$data = $this->validate();
|
||||
$service = $this->getCaptchaService();
|
||||
$service->verification($data['token'], $data['pointJson']);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success([]);
|
||||
}
|
||||
|
||||
protected function getCaptchaService()
|
||||
{
|
||||
$captchaType = request()->post('captchaType', null);
|
||||
$config = config('captcha');
|
||||
switch ($captchaType) {
|
||||
case "clickWord":
|
||||
$service = new ClickWordCaptchaService($config);
|
||||
break;
|
||||
case "blockPuzzle":
|
||||
$service = new BlockPuzzleCaptchaService($config);
|
||||
break;
|
||||
default:
|
||||
throw new ParamException('captchaType参数不正确!');
|
||||
}
|
||||
return $service;
|
||||
}
|
||||
|
||||
protected function validate()
|
||||
{
|
||||
return Request::instance()->validate([
|
||||
'token' => 'bail|required',
|
||||
'pointJson' => 'required',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
protected function success($data)
|
||||
{
|
||||
return [
|
||||
'error' => false,
|
||||
'repCode' => '0000',
|
||||
'repData' => $data,
|
||||
'repMsg' => null,
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function error($msg)
|
||||
{
|
||||
return [
|
||||
'error' => true,
|
||||
'repCode' => '6111',
|
||||
'repData' => null,
|
||||
'repMsg' => $msg,
|
||||
'success' => false,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
33
pro_v3.5.1/vendor/fastknife/ajcaptcha/test/laravel/captcha.php
vendored
Normal file
33
pro_v3.5.1/vendor/fastknife/ajcaptcha/test/laravel/captcha.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* 请将该文件放置于config目录
|
||||
*/
|
||||
return [
|
||||
'font_file' => '', //自定义字体包路径, 不填使用默认值
|
||||
//文字验证码
|
||||
'click_world' => [
|
||||
'backgrounds' => []
|
||||
],
|
||||
//滑动验证码
|
||||
'block_puzzle' => [
|
||||
'backgrounds' => [], //背景图片路径, 不填使用默认值
|
||||
'templates' => [], //模板图
|
||||
'offset' => 10, //容错偏移量
|
||||
],
|
||||
//水印
|
||||
'watermark' => [
|
||||
'fontsize' => 12,
|
||||
'color' => '#ffffff',
|
||||
'text' => '我的水印'
|
||||
],
|
||||
'cache' => [
|
||||
'constructor' => [\Illuminate\Support\Facades\Cache::class, 'store'],
|
||||
'method' => [
|
||||
'get' => 'get', //获取
|
||||
'set' => 'set', //设置
|
||||
'delete' => 'delete',//删除
|
||||
'has' => 'has' //key是否存在
|
||||
]
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user