mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]增加UTF8三十六进制加密与解密
This commit is contained in:
parent
d9cc3f3dce
commit
696493a0f9
@ -56,24 +56,30 @@ function & load_wechat($type = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全URL编码
|
* UTF8字符串加密
|
||||||
* @param array|string $data
|
* @param string $string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function encode($data) {
|
function encode($string) {
|
||||||
return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(serialize($data)));
|
$chars = '';
|
||||||
|
$len = strlen($string = iconv('utf-8', 'gbk', $string));
|
||||||
|
for ($i = 0; $i < $len; $i++) {
|
||||||
|
$chars .= str_pad(base_convert(ord($string[$i]), 10, 36), 2, 0, 0);
|
||||||
|
}
|
||||||
|
return strtoupper($chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 安全URL解码
|
* UTF8字符串解密
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function decode($string) {
|
function decode($string) {
|
||||||
$data = str_replace(['-', '_'], ['+', '/'], $string);
|
$chars = '';
|
||||||
$mod4 = strlen($data) % 4;
|
foreach (str_split($string, 2) as $char) {
|
||||||
!!$mod4 && $data .= substr('====', $mod4);
|
$chars .= chr(intval(base_convert($char, 36, 10)));
|
||||||
return unserialize(base64_decode($data));
|
}
|
||||||
|
return iconv('gbk', 'utf-8', $chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user