57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Tools;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Tools
|
|
{
|
|
|
|
//生成随机数
|
|
public static function generateRandStr($length = 8)
|
|
{
|
|
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789=-+';
|
|
$str = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$str .= $chars[mt_rand(0, strlen($chars) - 1)];
|
|
}
|
|
return $str;
|
|
}
|
|
|
|
static function filterDataParams($aData, $aParams)
|
|
{
|
|
foreach ($aParams as $sParam) {
|
|
if (isset($aData[$sParam])) {
|
|
$aData[$sParam] = self::hideStr($aData[$sParam]);
|
|
}
|
|
}
|
|
return $aData;
|
|
}
|
|
|
|
//字符串敏感部分中间隐藏
|
|
static function hideStr($sStr, $iStart = 5, $iEnd = 3, $sReplace = '*')
|
|
{
|
|
if (empty($sStr)) return $sStr;
|
|
$iStrLen = mb_strlen($sStr);
|
|
if ($iStrLen <= $iStart) return $sStr;
|
|
$iEnd = $iEnd > 0 ? $iEnd : $iStrLen - $iStart;
|
|
$sHideStr = '';
|
|
for ($i = 0; $i < $iEnd; $i++) {
|
|
$sHideStr .= $sReplace;
|
|
}
|
|
return mb_substr($sStr, 0, $iStart) . $sHideStr . mb_substr($sStr, $iStart + $iEnd);
|
|
}
|
|
|
|
static function getRandNum(): int
|
|
{
|
|
return rand(100000,999999);
|
|
}
|
|
|
|
static function genUuid(): string
|
|
{
|
|
return Str::orderedUuid();
|
|
}
|
|
|
|
|
|
|
|
}
|