This commit is contained in:
2023-12-17 21:29:59 +08:00
parent 3ae0046c88
commit ec6b900318
20 changed files with 652 additions and 31 deletions

43
app/Tools/Tools.php Normal file
View File

@ -0,0 +1,43 @@
<?php
namespace App\Tools;
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);
}
}