字符串隐藏

This commit is contained in:
taoser 2021-03-11 17:25:42 +08:00
parent 378ef5f3ab
commit 0786c89c38
2 changed files with 37 additions and 3 deletions

View File

@ -22,6 +22,7 @@ use think\exception\ValidateException;
use app\admin\controller\Uzip;
use think\facade\Cache;
use taoler\com\Api;
use taoler\com\Str;
use think\facade\Config;
class Upgrade extends AdminController
@ -43,9 +44,14 @@ class Upgrade extends AdminController
/** 升级界面 */
public function index()
{
$sys_version_num = Db::name('system')->field('sys_version_num,key,upcheck_url,upgrade_url')->find(1);
View::assign('ver_num',$sys_version_num);
{ //字符隐藏
$key = Str::func_substr_replace($this->sys['key']);
$sys_base = [
'key' => $key,
'upcheck_url' => $this->sys['upcheck_url'],
'upgrade_url' => $this->sys['upgrade_url'],
];
View::assign('ver_num',$sys_base);
return View::fetch();
}

28
extend/taoler/com/Str.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace taoler\com;
class Str
{
// 隐藏部分字符串
public static function func_substr_replace($str, $replacement = '*', $start = 5, $length = 30)
{
$len = mb_strlen($str,'utf-8');
if ($len > intval($start+$length)) {
$str1 = mb_substr($str,0,$start,'utf-8');
$str2 = mb_substr($str,intval($start+$length),NULL,'utf-8');
} else {
$str1 = mb_substr($str,0,1,'utf-8');
$str2 = mb_substr($str,$len-1,1,'utf-8');
$length = $len - 2;
}
$new_str = $str1;
for ($i = 0; $i < $length; $i++) {
$new_str .= $replacement;
}
$new_str .= $str2;
return $new_str;
}
}