You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
842 B
PHTML
41 lines
842 B
PHTML
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Controllers;
|
||
|
|
|
||
|
|
use App\Utils\Cookie;
|
||
|
|
use Minho\Captcha\CaptchaBuilder;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* ApiController
|
||
|
|
*/
|
||
|
|
|
||
|
|
class ApiController extends BaseController
|
||
|
|
{
|
||
|
|
public function createCaptch($request, $response, $args)
|
||
|
|
{
|
||
|
|
Cookie::startSession();
|
||
|
|
|
||
|
|
$captch = new CaptchaBuilder();
|
||
|
|
|
||
|
|
$captch->initialize([
|
||
|
|
'width' => 150,
|
||
|
|
'height' => 50,
|
||
|
|
'line' => true,
|
||
|
|
'curve' => false,
|
||
|
|
'noise' => 1,
|
||
|
|
// 可选:指定字体路径
|
||
|
|
// 'fonts' => [__DIR__ . '/../resources/fonts/arial.ttf']
|
||
|
|
]);
|
||
|
|
|
||
|
|
$captch->create();
|
||
|
|
|
||
|
|
$_SESSION['captch'] = $captch->getText();
|
||
|
|
|
||
|
|
// 设置响应类型为图片
|
||
|
|
header('Content-Type: image/jpeg');
|
||
|
|
|
||
|
|
$captch->output();
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
}
|