165 lines
4.9 KiB
PHP
165 lines
4.9 KiB
PHP
<?php
|
||
if ( ! function_exists('aes_encrypt')){
|
||
function aes_encrypt($orig_data, $key, $iv = '', $raw = false) {
|
||
$mode = MCRYPT_MODE_CBC;
|
||
if($iv == 'ecb') {
|
||
$iv = str_repeat("0", 16);
|
||
$mode = MCRYPT_MODE_ECB;
|
||
}
|
||
$encrypter = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
||
|
||
$blocksize = mcrypt_enc_get_block_size($encrypter);
|
||
$padding = $blocksize - strlen($orig_data) % $blocksize;
|
||
$padding_text = str_repeat(chr($padding), $padding);
|
||
$orig_data .= $padding_text;
|
||
|
||
|
||
if(!$iv) $iv = substr($key, 0, 16);
|
||
mcrypt_generic_init($encrypter, $key, $iv);
|
||
$ciphertext = mcrypt_generic($encrypter, $orig_data);
|
||
mcrypt_generic_deinit($encrypter);
|
||
mcrypt_module_close($encrypter);
|
||
if(!$raw) $ciphertext = base64_encode($ciphertext);
|
||
return $ciphertext;
|
||
}
|
||
}
|
||
if ( ! function_exists('aes_decrypt')){
|
||
function aes_decrypt($ciphertext, $key, $iv = '', $raw = false) {
|
||
if($ciphertext == '') return false;
|
||
$mode = MCRYPT_MODE_CBC;
|
||
if($iv == 'ecb') {
|
||
$iv = str_repeat("0", 16);
|
||
$mode = MCRYPT_MODE_ECB;
|
||
}
|
||
|
||
$encrypter = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', $mode, '');
|
||
if(!$raw) $ciphertext = base64_decode($ciphertext);
|
||
|
||
if(!$iv) $iv = substr($key, 0, 16);
|
||
mcrypt_generic_init($encrypter, $key, $iv);
|
||
$orig_data = mdecrypt_generic($encrypter, $ciphertext);
|
||
mcrypt_generic_deinit($encrypter);
|
||
mcrypt_module_close($encrypter);
|
||
$length = strlen($orig_data);
|
||
$unpadding = ord($orig_data[$length - 1]);
|
||
return substr($orig_data, 0, $length - $unpadding);
|
||
}
|
||
}
|
||
|
||
function dbenc($s) {
|
||
$db_enkey = "b9fc66957a4e5dbb";
|
||
if($db_enkey) {
|
||
$s = "genc_".aes_encrypt($s, $db_enkey);
|
||
}
|
||
return $s;
|
||
}
|
||
function dbdec($s) {
|
||
$db_enkey = "b9fc66957a4e5dbb";
|
||
if($db_enkey) {
|
||
if(strpos($s, 'genc_') === 0) $s = substr($s, 5);
|
||
$s = aes_decrypt($s, $db_enkey);
|
||
}
|
||
return $s;
|
||
}
|
||
|
||
/*
|
||
* $paramRow Ҫ<><D2AA><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD>
|
||
* $where Ҫ<><D2AA><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* */
|
||
function dbDecodeParam($paramRow,$where){
|
||
$paramRow = json_decode($paramRow);
|
||
$param = array();
|
||
foreach ($paramRow as $rk => $rv){
|
||
foreach ($rv as $k =>$v){
|
||
switch ($rk) {
|
||
case 'equal':
|
||
if (strstr($where,$k)) $param['equal'][$k] = dbdec($v);
|
||
else $param['equal'][$k] = $v;
|
||
break;
|
||
case 'like':
|
||
if (strstr($where,$k)) $param['like'][$k] = dbdec($v);
|
||
else $param['like'][$k] = $v;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
$param = json_encode($param);
|
||
return $param;
|
||
}
|
||
|
||
if(!function_exists("gquery")) {
|
||
function gquery($url, $post = array(), $header = array())
|
||
{
|
||
$c = curl_init($url);
|
||
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
||
if(defined("COOKIEJAR")) {
|
||
curl_setopt($c, CURLOPT_COOKIEJAR, COOKIEJAR);
|
||
curl_setopt($c, CURLOPT_COOKIEFILE, COOKIEJAR);
|
||
}
|
||
if($header) curl_setopt($c, CURLOPT_HTTPHEADER, $header);
|
||
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
|
||
curl_setopt($c, CURLOPT_AUTOREFERER, 1);
|
||
curl_setopt($c, CURLOPT_TIMEOUT, 30);
|
||
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
|
||
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
|
||
if($post) {
|
||
if(is_array($post)) {
|
||
$poststr = $post;
|
||
} else {
|
||
$poststr = $post;
|
||
}
|
||
curl_setopt($c, CURLOPT_POST, 1);
|
||
curl_setopt($c, CURLOPT_POSTFIELDS, $poststr);
|
||
}
|
||
|
||
$content = curl_exec($c);
|
||
curl_close($c);
|
||
return $content;
|
||
}
|
||
}
|
||
|
||
if(!function_exists('cutName')) {
|
||
function cutName($user_name, $type = 'username') {
|
||
$strlen = mb_strlen($user_name, 'utf-8');
|
||
if ($type == 'cellphone') {
|
||
$firstStr = mb_substr($user_name, 0, 3, 'utf-8');
|
||
$lastStr = mb_substr($user_name, -4, 4, 'utf-8');
|
||
return $firstStr . '****' . $lastStr;
|
||
}
|
||
$firstStr = mb_substr($user_name, 0, 1, 'utf-8');
|
||
$lastStr = mb_substr($user_name, -1, 1, 'utf-8');
|
||
if ($strlen == 2) {
|
||
return $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1);
|
||
} elseif ($strlen == 1) {
|
||
return $user_name;
|
||
} elseif ($strlen == 0) {
|
||
return "*";
|
||
} else {
|
||
return $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!function_exists('cleanInput')) {
|
||
function cleanInput($data){
|
||
// 去除字符串两边的空格
|
||
$data = trim($data);
|
||
|
||
// 去除反斜杠(对魔术引号进行处理)
|
||
if (get_magic_quotes_gpc()) {
|
||
$data = stripslashes($data);
|
||
}
|
||
|
||
// 转换特殊字符为HTML实体
|
||
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
||
|
||
// 可选:对数据进行过滤,移除HTML标签
|
||
// $data = strip_tags($data);
|
||
|
||
// 可选:使用filter_var进行过滤
|
||
// $data = filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS);
|
||
|
||
return $data;
|
||
}
|
||
}
|