Skip to content

Commit

Permalink
新增hash方法
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Jul 28, 2020
1 parent d653039 commit d79497d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
56 changes: 30 additions & 26 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,33 @@
*/
class Result
{
private $CaptchaByte; // 验证码图片
private $CaptchaMime; // 验证码类型
private $CaptchaCode; // 验证码内容
private $CaptchaFile; // 验证码文件
private $captchaByte; // 验证码图片
private $captchaMime; // 验证码类型
private $captchaCode; // 验证码内容
private $createTime;

function __construct($Byte, $Code, $Mime,$File)
function __construct($Byte, $Code, $Mime)
{
$this->CaptchaByte = $Byte;
$this->CaptchaMime = $Mime;
$this->CaptchaCode = $Code;
$this->CaptchaFile = $File;
$this->captchaByte = $Byte;
$this->captchaMime = $Mime;
$this->captchaCode = $Code;
$this->createTime = time();
}

function getCreateTime():int
{
return $this->createTime;
}

function getCodeHash($code = null,$time = null)
{
if(!$code){
$code = $this->captchaCode;
}
if(!$time){
$time = $this->createTime;
}
return substr(md5($code.$time),8,16);
}

/**
Expand All @@ -37,7 +53,7 @@ function __construct($Byte, $Code, $Mime,$File)
*/
function getImageByte()
{
return $this->CaptchaByte;
return $this->captchaByte;
}

/**
Expand All @@ -47,8 +63,8 @@ function getImageByte()
*/
function getImageBase64()
{
$base64Data = base64_encode($this->CaptchaByte);
$Mime = $this->CaptchaMime;
$base64Data = base64_encode($this->captchaByte);
$Mime = $this->captchaMime;
return "data:{$Mime};base64,{$base64Data}";
}

Expand All @@ -59,7 +75,7 @@ function getImageBase64()
*/
function getImageCode()
{
return $this->CaptchaCode;
return $this->captchaCode;
}

/**
Expand All @@ -68,18 +84,6 @@ function getImageCode()
*/
function getImageMime()
{
return $this->CaptchaMime;
}

/**
* 获取验证码文件路径
* @author: eValor < [email protected] >
*/
function getImageFile()
{
if(!file_exists($this->CaptchaFile)){
file_put_contents($this->CaptchaFile, $this->CaptchaByte);
}
return $this->CaptchaFile;
return $this->captchaMime;
}
}
10 changes: 1 addition & 9 deletions src/VerifyCode.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?php
// +----------------------------------------------------------------------
// | easySwoole [ use swoole easily just like echo "hello world" ]
// +----------------------------------------------------------------------
// | WebSite: https://www.easyswoole.com
// +----------------------------------------------------------------------
// | Welcome Join QQGroup 633921431
// +----------------------------------------------------------------------

namespace EasySwoole\VerifyCode;

Expand Down Expand Up @@ -80,14 +73,13 @@ function DrawCode($Code = null)
// 输出验证码结果集
$this->temp = rtrim(str_replace('\\', '/', $this->temp), '/') . '/';
mt_srand();
$filePath = $this->temp . date('YmdHis') . rand(1000,9999) .'.'.MIME::getExtensionName($this->mime);
$func = 'image' . MIME::getExtensionName($this->mime);
ob_start();
$func($this->imInstance);
$file = ob_get_contents();
ob_end_clean();
imagedestroy($this->imInstance);
return new Result($file, $Code, $this->mime, $filePath);
return new Result($file, $Code, $this->mime);
}

/**
Expand Down

0 comments on commit d79497d

Please sign in to comment.