作者:chenliuyan13 | 来源:互联网 | 2023-09-18 15:29
functionencode($result_array){global$key;//JSON_PRETTY_PRINTJSON_UNESCAPED_UNICODE$
function encode($result_array) {
global $key;//JSON_PRETTY_PRINT JSON_UNESCAPED_UNICODE
$result = json_encode($result_array, JSON_UNESCAPED_UNICODE);
//$result = str_replace(":null", ':""', $result);
$str = $result;
$block = mcrypt_get_block_size('des', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
$encode = base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB));
return $encode;
}
//echo $str;exit;
function decode($str) {
global $key;
$encode = $str;
$json = mcrypt_decrypt(MCRYPT_DES, $key, base64_decode($encode), MCRYPT_MODE_ECB);
$block = mcrypt_get_block_size('des', 'ecb');
$pad = ord($json[($len = strlen($json)) - 1]);
$json = substr($json, 0, strlen($json) - $pad);
return $json;
function _encrypt($str)
{
global $key;
$block = mcrypt_get_block_size('des', 'ecb');
$pad = $block - (strlen($str) % $block);
$str .= str_repeat(chr($pad), $pad);
return base64_encode(mcrypt_encrypt(MCRYPT_DES, $key, $str, MCRYPT_MODE_ECB));