From 696493a0f9295cb3c206ecb9a2e62a48c527fe90 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 26 Jun 2017 13:31:07 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E5=A2=9E=E5=8A=A0UTF8?= =?UTF-8?q?=E4=B8=89=E5=8D=81=E5=85=AD=E8=BF=9B=E5=88=B6=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E4=B8=8E=E8=A7=A3=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/application/common.php b/application/common.php index d6e57edab..64aa56389 100644 --- a/application/common.php +++ b/application/common.php @@ -56,24 +56,30 @@ function & load_wechat($type = '') { } /** - * 安全URL编码 - * @param array|string $data + * UTF8字符串加密 + * @param string $string * @return string */ -function encode($data) { - return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode(serialize($data))); +function encode($string) { + $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 * @return string */ function decode($string) { - $data = str_replace(['-', '_'], ['+', '/'], $string); - $mod4 = strlen($data) % 4; - !!$mod4 && $data .= substr('====', $mod4); - return unserialize(base64_decode($data)); + $chars = ''; + foreach (str_split($string, 2) as $char) { + $chars .= chr(intval(base_convert($char, 36, 10))); + } + return iconv('gbk', 'utf-8', $chars); } /**