This commit is contained in:
2021-07-13 17:15:07 +08:00
parent 250b5b0928
commit 3009c3fcf0
3 changed files with 16 additions and 18 deletions
+4 -4
View File
@@ -18,7 +18,7 @@ class Reader
* @param int $size * @param int $size
* @return array and int * @return array and int
*/ */
public static function readerServerLogPagination($filepath, $page = 1, $size = 20): array public static function readerServerLogPagination($filepath, int $page = 1, int $size = 20): array
{ {
$count = 0; $count = 0;
$strings = []; $strings = [];
@@ -54,9 +54,9 @@ class Reader
* @param $filename * @param $filename
* @param $start * @param $start
* @param $lines * @param $lines
* @return mixed * @return array
*/ */
public static function read_backward_line($filename, $start, $lines): mixed public static function read_backward_line($filename, $start, $lines): array
{ {
$lines++; $lines++;
$offset = -1; $offset = -1;
@@ -123,7 +123,7 @@ class Reader
* @param int $size * @param int $size
* @return array * @return array
*/ */
public static function folderPagination($filepath, $page = 1, $size = 20): array public static function folderPagination($filepath, int $page = 1, int $size = 20): array
{ {
$count = 0; $count = 0;
$strings = []; $strings = [];
+8 -12
View File
@@ -30,9 +30,7 @@ class Str
if ($length < 1) $length = 20; if ($length < 1) $length = 20;
$default = self::STRING . strtoupper(self::STRING) . self::NUMBER; $default = self::STRING . strtoupper(self::STRING) . self::NUMBER;
$default = str_split($default); $default = str_split($default);
for ($i = 0; $i < $length; $i++) { $string .= str_repeat($default[array_rand($default)], $length);
$string .= $default[array_rand($default)];
}
return (string)$string; return (string)$string;
} }
@@ -47,9 +45,7 @@ class Str
$number = ''; $number = '';
$default = str_split(self::NUMBER); $default = str_split(self::NUMBER);
if ($length < 1) $length = 1; if ($length < 1) $length = 1;
for ($i = 0; $i < $length; $i++) { $number .= str_repeat($default[array_rand($default)], $length);
$number .= $default[array_rand($default)];
}
return $number; return $number;
} }
@@ -61,7 +57,7 @@ class Str
* *
* @return string * @return string
*/ */
public static function cut_str_utf8($string, $sullen, $strip_tags = true, $append = '...'): string public static function cut_str_utf8($string, $sullen, bool $strip_tags = true, string $append = '...'): string
{ {
if ($strip_tags) { if ($strip_tags) {
$string = strip_tags($string); $string = strip_tags($string);
@@ -119,7 +115,7 @@ class Str
* @param string $append * @param string $append
* @return string * @return string
*/ */
public static function cut($string, int $length = 20, $append = '...'): string public static function cut($string, int $length = 20, string $append = '...'): string
{ {
if (empty($string)) { if (empty($string)) {
return ''; return '';
@@ -145,7 +141,7 @@ class Str
* *
* @return string * @return string
*/ */
public static function encrypt($str, $number = 10, $key = 'xshucai.com'): string public static function encrypt($str, int $number = 10, string $key = 'xshucai.com'): string
{ {
$res = []; $res = [];
$add = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $add = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
@@ -243,13 +239,13 @@ class Str
* @return string * @return string
* @throws Exception * @throws Exception
*/ */
public static function token(int $user, $param = [], $requestTime = NULL): string public static function token(int $user, array $param = [], $requestTime = NULL): string
{ {
$str = ''; $str = '';
if (!$requestTime) { if (!$requestTime) {
$requestTime = microtime(true); $requestTime = microtime(true);
} }
$_user = str_split(md5($user . md5($user))); $_user = str_split(md5($user . md5((string)$user)));
ksort($_user); ksort($_user);
foreach ($_user as $key => $val) { foreach ($_user as $key => $val) {
$str .= md5(sha1($key . $val . 'www.xshucai.com')); $str .= md5(sha1($key . $val . 'www.xshucai.com'));
@@ -259,7 +255,7 @@ class Str
$str .= md5($str . sha1($key . md5($val))); $str .= md5($str . sha1($key . md5($val)));
} }
} }
$str .= sha1(base64_encode($requestTime)); $str .= sha1(base64_encode((string)$requestTime));
$md5 = md5($str . $user); $md5 = md5($str . $user);
+4 -2
View File
@@ -76,6 +76,7 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
/** /**
* @throws ConfigException * @throws ConfigException
* @throws Exception
*/ */
public function init() public function init()
{ {
@@ -235,9 +236,10 @@ mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
if (!openssl_public_decrypt(base64_decode($headers['refresh']), $data, $this->public)) { if (!openssl_public_decrypt(base64_decode($headers['refresh']), $data, $this->public)) {
throw new AuthException('信息解码失败.'); throw new AuthException('信息解码失败.');
} }
$data = Json::decode($data, true); $data = Json::decode($data, true);
if (!isset($headers['token']) || $data['token'] != $headers['token']) {
throw new AuthException('信息解码失败.');
}
return (int)$data['user']; return (int)$data['user'];
} }