src/Biz/Common/BizCaptcha.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Biz\Common;
use Codeages\Biz\Framework\Context\BizAware;
class BizCaptcha extends BizAware
{
const STATUS_SUCCESS = 'success';
const STATUS_INVALID = 'invalid';
const STATUS_EXPIRED = 'expired';
private $tokenType = 'captcha';
/**
* @var \Gregwar\Captcha\CaptchaBuilder
*/
protected $captchaBuilder;
public function generate($options = array())
{
$options = array_merge(array('width' => 150, 'height' => 32, 'quality' => 90, 'verify_times' => 10), $options);
$this->captchaBuilder->build($options['width'], $options['height'], null, null);
$token = $this->getTokenService()->makeToken($this->tokenType, array(
'times' => $options['verify_times'],
'duration' => 60 * 30,
'userId' => 0,
'data' => array(
'phrase' => $this->captchaBuilder->getPhrase(),
),
));
return array('image' => $this->captchaBuilder->inline($options['quality']), 'captchaToken' => $token['token']);
}
public function check($captchaId, $phrase)
{
$token = $this->getTokenService()->verifyToken($this->tokenType, $captchaId);
if (empty($token)) {
return self::STATUS_INVALID;
}
$remainedTimes = $token['remainedTimes'];
if (0 == $remainedTimes) {
return self::STATUS_EXPIRED;
}
return $token['data']['phrase'] == $phrase ? self::STATUS_SUCCESS : self::STATUS_INVALID;
}
public function setCaptchaBuilder($captchaBuilder)
{
$this->captchaBuilder = $captchaBuilder;
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。