// 加密 解密
function passport_encrypt($txt, $key = 'liiu') {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = '';
for($i = 0;$i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
return urlencode(base64_encode(passport_key($tmp, $key)));
}
function passport_decrypt($txt, $key = 'liiu') {
$txt = passport_key(base64_decode(urldecode($txt)), $key);
$tmp = '';
for($i = 0;$i < strlen($txt); $i++) {
$md5 = $txt[$i];
$tmp .= $txt[++$i] ^ $md5;
}
return $tmp;
}
function passport_key($txt, $encrypt_key) {
$encrypt_key = md5($encrypt_key);
$ctr = 0;
$tmp = '';
for($i = 0; $i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
$txt = '1AC@#$woshi我谁是否是2131***哈哈';
$key = "testkey";
$encrypt = passport_encrypt($txt,$key);
$decrypt = passport_decrypt($encrypt,$key);
var_dump($encrypt);
var_dump($decrypt);
// 替换 * 显示 脱敏函数
function desensitize($string, $start = 0, $length = 0, $re = '*'){
if(empty($string) || empty($length) || empty($re)) return $string;
$end = $start + $length;
$strlen = mb_strlen($string);
$str_arr = array();
for($i=0; $i<$strlen; $i++) {
if($i>=$start && $i<$end)
$str_arr[] = $re;
else
$str_arr[] = mb_substr($string, $i, 1);
}
return implode('',$str_arr);
}
$name = '王刚';
$mobile = '13817558198';
$name = desensitize($name,1,2);
$mobile = desensitize($mobile,3,4);
var_dump($name);
var_dump($mobile);
$date=date("Y-m-d H:i:s",strtotime("- 90 day"));
echo $date;