2024-04-01 15:54:27 +08:00
|
|
|
<?php
|
|
|
|
function getByPage($sql, $page = 1, $pagesize = 15, &$pageinfo = array(), $link = null)
|
|
|
|
{
|
|
|
|
$page = max(intval($page), 1);
|
|
|
|
$pagesize = intval($pagesize);
|
|
|
|
if(!$pagesize) $pagesize = 15;
|
|
|
|
if($link) $rs = mysql_query($sql, $link);
|
|
|
|
else $rs = mysql_query($sql);
|
|
|
|
if(!$rs) return false;
|
|
|
|
$numRows = mysql_num_rows($rs);
|
|
|
|
if($numRows == 0) {
|
|
|
|
$pageinfo['pagecount'] = 0;
|
|
|
|
$pageinfo['count'] = 0;
|
|
|
|
$pageinfo['page'] = 1;
|
|
|
|
$pageinfo['pagesize'] = $pagesize;
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
if($pagesize !== 0) {
|
|
|
|
$pagesize = intval($pagesize);
|
|
|
|
if($pagesize == "" || $pagesize < 0) $pagesize = 15;
|
|
|
|
$pagecount = ceil($numRows / $pagesize);
|
|
|
|
if($page == -1) $page = $pagecount;
|
|
|
|
$page = intval($page);
|
|
|
|
if(!$page || $page < 0) $page = 1;
|
|
|
|
if($page > $pagecount) $page = $pagecount;
|
|
|
|
mysql_data_seek($rs, ($page - 1) * $pagesize);
|
|
|
|
}
|
|
|
|
$data = array();
|
|
|
|
$n = 0;
|
|
|
|
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
|
|
|
|
$data[] = $row;
|
|
|
|
$n++;
|
|
|
|
if($pagesize != 0 && $n >= $pagesize) break;
|
|
|
|
}
|
|
|
|
$pageinfo['pagecount'] = $pagecount;
|
|
|
|
$pageinfo['count'] = $numRows;
|
|
|
|
$pageinfo['page'] = $page;
|
|
|
|
$pageinfo['pagesize'] = $pagesize;
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
function getByPageSql($sql, $page, $pagesize, &$pageinfo = array())
|
|
|
|
{
|
|
|
|
if($page != -1) $page = max(intval($page), 1);
|
|
|
|
$pagesize = max(intval($pagesize), 10);
|
|
|
|
$sk = md5($sql);
|
|
|
|
$cInfo = $_SESSION['sqlCountInfo'][$sk];
|
|
|
|
if($cInfo && time() - $cInfo['time'] < 300) {
|
|
|
|
$numRows = intval($cInfo['count']);
|
|
|
|
} else {
|
|
|
|
$p1 = stripos($sql, "from");
|
|
|
|
$sqlc = "select count(*) " . substr($sql, $p1);
|
|
|
|
$po = stripos($sqlc, "order by");
|
|
|
|
if($po) $sqlc = substr($sqlc, 0, $po);
|
|
|
|
$rs = $GLOBALS['db']->query($sqlc);
|
|
|
|
if(!$rs) return array();
|
|
|
|
$numRows = $rs->fetchColumn();
|
|
|
|
$cInfo = array('count'=>$numRows, 'time'=>time());
|
|
|
|
$_SESSION['sqlCountInfo'][$sk] = $cInfo;
|
|
|
|
}
|
|
|
|
if($numRows == 0) {
|
|
|
|
$pageinfo['pagecount'] = 0;
|
|
|
|
$pageinfo['count'] = 0;
|
|
|
|
$pageinfo['page'] = 1;
|
|
|
|
$pageinfo['pagesize'] = $pagesize;
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$pagecount = ceil($numRows / $pagesize);
|
|
|
|
if($page == -1) $page = $pagecount;
|
|
|
|
$pageinfo['pagecount'] = $pagecount;
|
|
|
|
$pageinfo['count'] = $numRows;
|
|
|
|
$pageinfo['page'] = $page;
|
|
|
|
$pageinfo['pagesize'] = $pagesize;
|
|
|
|
|
|
|
|
$start = ($page-1) * $pagesize;
|
|
|
|
$end = $start + $pagesize;
|
|
|
|
$sql = substr(trim($sql), 7);
|
|
|
|
$sql = "select *
|
|
|
|
from (
|
|
|
|
select row_number() over(order by __tc__)__rn__,*
|
|
|
|
from (select top {$end} 0 __tc__,{$sql})t
|
|
|
|
)tt
|
|
|
|
where __rn__>{$start}";
|
|
|
|
//die($sql);
|
|
|
|
$rs = $GLOBALS['db']->query($sql);
|
|
|
|
if($rs === false) return array();
|
|
|
|
return $rs->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
}
|
|
|
|
function gpageHTML($page, $pagecount, $total, $url, $N = 5)
|
|
|
|
{
|
|
|
|
$page = intval($page);
|
|
|
|
$html = "";
|
|
|
|
|
|
|
|
if($url == '') {
|
|
|
|
$qs = $_SERVER['QUERY_STRING'];
|
|
|
|
$qs = "act=listsp&listtype=1&s_text=&rduser=&page=";
|
|
|
|
$qs = preg_replace("/page=(\d+)?\&?/", "", $qs);
|
|
|
|
if(substr($qs, 0, 1) == '&') $qs = substr($qs, 1);
|
|
|
|
if(substr($qs, strlen($qs)-1) == '&') $qs = substr($qs, 0, strlen($qs)-1);
|
|
|
|
if($qs == '') $url = "?page=%s";
|
|
|
|
else $url = "?{$qs}&page=%s";
|
|
|
|
|
|
|
|
}
|
|
|
|
$n = floor(($N - 1) / 2);
|
|
|
|
$pos1 = $page - $n;
|
|
|
|
$pos2 = $page + $n;
|
|
|
|
if($N % 2 == 0) $pos2++;
|
|
|
|
if($pos1 <= 0) {
|
|
|
|
$pos2 += abs($pos1) + 1;
|
|
|
|
$pos1 = 1;
|
|
|
|
}
|
|
|
|
if($pos2 > $pagecount) {
|
|
|
|
$pos1 -= ($pos2 - $pagecount);
|
|
|
|
}
|
|
|
|
if($page != 1 && $pos1 > 1)
|
|
|
|
$html .= '<a href="' . str_replace("%s", strval($page - 1), $url) . '">上一页</a> <a href="' . str_replace("%s", strval(1), $url) . '">1</a> ... ';
|
|
|
|
for($i = $pos1; $i <= $pos2; $i++) {
|
|
|
|
if($i >= 1 && $i <= $pagecount) {
|
|
|
|
if($page == $i) {
|
|
|
|
$html .= ' ' . $i . ' ';
|
|
|
|
} else {
|
|
|
|
$html .= '<a href="' . str_replace("%s", strval($i), $url) . '">' . $i . '</a> ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($page != $pagecount) {
|
|
|
|
$html .= ' ... <a href="' . str_replace("%s", strval($pagecount), $url) . '">'.$pagecount.'</a> <a href="' . str_replace("%s", strval($page + 1), $url) . '">下一页</a> ';
|
|
|
|
}
|
|
|
|
$html .= " {$page}/{$pagecount}页 共{$total}条记录 ";
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
function gbk2utf8($data) {
|
|
|
|
if(is_array($data)) {
|
|
|
|
foreach($data as $key => $item) {
|
|
|
|
if(is_string($key)) {
|
|
|
|
unset($data[$key]);
|
|
|
|
$key = iconv('gbk','utf-8',$key);
|
|
|
|
}
|
|
|
|
$data[$key] = gbk2utf8($item);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
return iconv('gbk','utf-8',$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function gurl_par($par, $url = '')
|
|
|
|
{
|
|
|
|
if($url == '') $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
|
|
|
|
$pos = strpos($url, '?');
|
|
|
|
if($pos === false)
|
|
|
|
{
|
|
|
|
$url .= '?'.$par;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$querystring = substr(strstr($url, '?'), 1);
|
|
|
|
parse_str($par, $pars);
|
|
|
|
foreach($pars as $k=>$v)
|
|
|
|
{
|
|
|
|
$querystring = g_url_par($k, $v, $querystring);
|
|
|
|
}
|
|
|
|
$url = substr($url, 0, $pos).'?'.$querystring;
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
function g_url_par($var, $value, $querystring)
|
|
|
|
{
|
|
|
|
if($querystring)
|
|
|
|
{
|
|
|
|
$pattern = "/([&]?)(".preg_quote($var)."\=)([^&]*)([&]?)/";
|
|
|
|
$querystring = preg_match($pattern, $querystring) ? preg_replace($pattern, '${1}${2}'.$value.'${4}', $querystring) : $querystring."&$var=$value";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$querystring = $var.'='.$value;
|
|
|
|
}
|
|
|
|
return $querystring;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!function_exists("getip")) {
|
|
|
|
function getip()
|
|
|
|
{
|
|
|
|
if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
|
|
|
|
$onlineip = getenv('HTTP_CLIENT_IP');
|
|
|
|
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
|
|
|
|
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
|
|
|
|
$onlineip = getenv('REMOTE_ADDR');
|
|
|
|
} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
|
|
|
|
$onlineip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
}
|
|
|
|
return $onlineip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function gselectmenu($resouce,$selectname,$optionname,$optionvalue,$selectindex,$jsfunction="") {
|
|
|
|
$returnstr = "<select name='{$selectname}' onchange='{$jsfunction}'>";
|
|
|
|
//$returnstr.= "<option value='-9999'>?????</option>";
|
|
|
|
|
|
|
|
foreach($resouce as $key=>$value) {
|
|
|
|
if($optionname=="value") {
|
|
|
|
$selected = (strcmp($key,$selectindex)==0)?"selected":"";
|
|
|
|
$returnstr.= "<option value='{$key}' {$selected}>{$value}</option>";
|
|
|
|
} else {
|
|
|
|
$selected = (strcmp($value,$selectindex)==0)?"selected":"";
|
|
|
|
$returnstr.= "<option value='{$value}' {$selected}>{$key}</option>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$returnstr.= "</select>".chr(10).chr(13);
|
|
|
|
|
|
|
|
return $returnstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function galert($msg, $location = '', $fyzm = '')
|
|
|
|
{
|
|
|
|
if($location) $l = "location.href='{$location}';";
|
|
|
|
else if($location===0) $l = "window.close();";
|
|
|
|
else {
|
|
|
|
$l = "history.back();";
|
|
|
|
if($fyzm) $l.="$('yzmimg').src=$('yzmimg').src;";
|
|
|
|
}
|
|
|
|
$msg = str_replace('"','\\"', $msg);
|
|
|
|
$html = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">alert("'.$msg.'");'.$l.'</script>';
|
|
|
|
echo $html;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gredirect($url)
|
|
|
|
{
|
|
|
|
@header("Location: " . $url);
|
|
|
|
echo '<meta http-equiv="refresh" content="0; url='.$url.'" />';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function gstr_cut($str, $len, $c = "..", &$iscut = false, &$cutstr = '')
|
|
|
|
{
|
|
|
|
$l = mb_strlen($str, 'gbk');
|
|
|
|
$iscut = false;
|
|
|
|
if($l > $len) {
|
|
|
|
$iscut = true;
|
|
|
|
$cutstr = mb_substr($str, $len - 1, $l-$len+1, 'gbk');
|
|
|
|
$str = mb_substr($str, 0, $len-1, 'gbk') . $c;
|
|
|
|
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
function toHTML($str)
|
|
|
|
{
|
|
|
|
$str = preg_replace("/^( |??)*(.+)/m", "????$2", trim(strip_tags($str)));
|
|
|
|
$str = str_replace("\n", "<br />", $str);
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cookie($name, $value, $time = 0)
|
|
|
|
{
|
|
|
|
$host = $_SERVER['HTTP_HOST'];
|
|
|
|
$a = explode(".", $host);
|
|
|
|
$a = array_slice($a, count($a) - 2);
|
|
|
|
$domain = "." . implode(".", $a);
|
|
|
|
|
|
|
|
@setcookie($name, $value, $time, "/", $domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
function gdownload($path, $fn = '')
|
|
|
|
{
|
|
|
|
if(substr($path, 0, 7) == 'http://') {
|
|
|
|
|
|
|
|
header("Location: " . $path);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$mime = array(
|
|
|
|
'zip' => 'application/x-zip-compressed',
|
|
|
|
'wma' => 'audio/x-ms-wma',
|
|
|
|
'mp3' => 'audio/mpeg',
|
|
|
|
'rar' => 'application/octet-stream',
|
|
|
|
'jar' => 'application/java-archive',
|
|
|
|
'apk' => 'application/vnd.android.package-archive',
|
|
|
|
'cab' => 'application/octet-stream',
|
|
|
|
'doc' => 'application/msword',
|
|
|
|
'xls' => 'application/vnd.ms-excel',
|
|
|
|
'pdf' => 'application/pdf',
|
|
|
|
'ppt' => 'application/vnd.ms-powerpoint',
|
|
|
|
);
|
|
|
|
if(!is_file($path)) return false;
|
|
|
|
$ext = strtolower(end(explode(".", $path)));
|
|
|
|
set_time_limit(600);
|
|
|
|
if($fn) $filename = urlencode(iconv("gbk", "utf-8", $fn) . "." . $ext);
|
|
|
|
else $filename = urlencode(iconv("gbk", "utf-8", basename($path)));
|
|
|
|
header("Cache-Control: public, must-revalidate");
|
|
|
|
header("Pragma: hack");
|
|
|
|
$mm = $mime[$ext];
|
|
|
|
if(!$mm) $mm = "pplication/octet-stream";
|
|
|
|
header("Content-Type: " . $mm);
|
|
|
|
header("Content-Length: " . filesize($path));
|
|
|
|
header("Content-Disposition: attachment; filename={$filename}");
|
|
|
|
header("Content-Transfer-Encoding: binary");
|
|
|
|
header("Connection: close");
|
|
|
|
$f = fopen($path, "r");
|
|
|
|
if(!$f) return false;
|
|
|
|
while($s = fread($f, 8192)) {
|
|
|
|
echo $s;
|
|
|
|
unset($s);
|
|
|
|
}
|
|
|
|
fclose($f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
class GYHJSON {
|
|
|
|
static $isconv = -1;
|
|
|
|
public static function encode($var, $_isconv = 0){
|
|
|
|
if(self::$isconv == -1) self::$isconv = $_isconv;
|
|
|
|
switch (gettype($var)){
|
|
|
|
case 'boolean':
|
|
|
|
return $var ? 'true' : 'false';
|
|
|
|
|
|
|
|
case 'NULL':
|
|
|
|
return 'null';
|
|
|
|
|
|
|
|
case 'integer':
|
|
|
|
return (int) $var;
|
|
|
|
|
|
|
|
case 'double':
|
|
|
|
case 'float':
|
|
|
|
return (float) $var;
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
if(self::$isconv == 1) $var = iconv("gbk", "utf-8", $var);
|
|
|
|
return '"' . preg_replace(array("/(?<=([".chr(0x81)."-".chr(0xff)."][".chr(0x40)."-".chr(0xff)."])|[".chr(0x1)."-".chr(0x7e)."]|^)\\\/", "|\"|", "|\n|", "|".chr(0x8)."|", "|\r|", "|\t|", "|[".chr(0x1)."-".chr(0x1f)."]|e"), array('\\\\\\', '\"', '\n', '\b', '\r', '\t', "'\u00' . bin2hex('$0')"), $var) . '"';
|
|
|
|
|
|
|
|
case 'array':
|
|
|
|
if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) {
|
|
|
|
$prop= array_map(array("self", "_name_value"), array_keys($var), array_values($var));
|
|
|
|
return '{' . join(',', $prop) . '}';
|
|
|
|
}
|
|
|
|
$element = array_map(array("self", "encode"), $var);
|
|
|
|
return '[' . join(',', $element) . ']';
|
|
|
|
|
|
|
|
case 'object':
|
|
|
|
$vars = get_object_vars($var);
|
|
|
|
$prop= array_map(array("self", '_name_value'), array_keys($vars), array_values($vars));
|
|
|
|
return '{' . join(',', $prop) . '}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function _name_value($name, $value){
|
|
|
|
return self::encode(strval($name)) . ':' . self::encode($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function gjson($obj, $p = 1)
|
|
|
|
{
|
|
|
|
if(!$obj) $s = "[]";
|
|
|
|
//else if($_GET['jsongbk']) $s = GYHJSON::encode($obj);
|
|
|
|
else $s = json_encode(gbk2utf8($obj));
|
|
|
|
|
|
|
|
if($_GET['compress'] == 1) $s = gzencode($s, 5);
|
|
|
|
if($p) echo $s;
|
|
|
|
else return $s;
|
|
|
|
}
|
|
|
|
function getArrList($data, $key)
|
|
|
|
{
|
|
|
|
$arr = array();
|
|
|
|
foreach($data as $item) {
|
|
|
|
$arr[] = $item[$key];
|
|
|
|
}
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
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 = '';
|
|
|
|
foreach($post as $key => $item) {
|
|
|
|
$poststr .= "&" . $key . "=" . urlencode($item);
|
|
|
|
}
|
|
|
|
$poststr = substr($poststr, 1);
|
|
|
|
} else {
|
|
|
|
$poststr = $post;
|
|
|
|
}
|
|
|
|
curl_setopt($c, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $poststr);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = curl_exec($c);
|
|
|
|
curl_close($c);
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isPhone($num)
|
|
|
|
{
|
|
|
|
if(preg_match("/^1\d{10}$/", $num)) {
|
|
|
|
if(!strstr($num, "0000000"))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
function cnWeek($date)
|
|
|
|
{
|
|
|
|
$arr = array('日', '一', '二', '三', '四', '五', '六');
|
|
|
|
return $arr[date('w', $date)];
|
|
|
|
}
|
|
|
|
function dealChnUrl($s) {
|
|
|
|
$a = explode("/", $s);
|
|
|
|
$end = end($a);
|
|
|
|
if(strstr($end, "?")) return $s;
|
|
|
|
return substr($s, 0, strlen($s)-strlen($end)).urlencode(urldecode($end));
|
|
|
|
}
|
|
|
|
|
|
|
|
function ggetCutStr($content, $len)
|
|
|
|
{
|
|
|
|
$s = gstr_cut($content, $len, '', $iscut, $cutstr);
|
|
|
|
$s = htmlspecialchars($s);
|
|
|
|
if($iscut) {
|
|
|
|
$n = intval($GLOBALS['ghidespanN']);
|
|
|
|
$id = "ghidespan_" . $n;
|
|
|
|
$GLOBALS['ghidespanN'] = $n + 1;
|
|
|
|
$s = '<span id="'.$id.'_c">'.$s.'</span>';
|
|
|
|
$s .= '<span id="'.$id.'_dot">..</span>';
|
|
|
|
$s .= '<span style="display:none" id="'.$id.'">'.$cutstr.'</span>';
|
|
|
|
$s .= ' <a href="javascript:;" onClick="document.getElementById(\''.$id.'\').style.display=\'\';document.getElementById(\''.$id.'_dot\').style.display=\'none\';this.style.display=\'none\'" style="color:#0066ff;text-decoration:underline">???</a>';
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
function isdx($num)
|
|
|
|
{
|
|
|
|
$pre = substr($num, 0, 3);
|
|
|
|
if($pre == '133' || $pre == '189' || $pre == '153' || $pre == '180' || $pre == '181' || $pre == '177') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getlxdh($s)
|
|
|
|
{
|
|
|
|
$lxdh = '';
|
|
|
|
preg_match("/(^|[^\d])((189|133|153|180|181)\d{8})($|[^\d])/", $s, $m);
|
|
|
|
$lxdh = $m[2];
|
|
|
|
if(!$lxdh) {
|
|
|
|
preg_match("/(^|[^\d])(1\d{10})($|[^\d])/", $s, $m);
|
|
|
|
$lxdh = $m[2];
|
|
|
|
}
|
|
|
|
if(!$lxdh) {
|
|
|
|
preg_match("/(^|[^\d])(\d{8})($|[^\d])/", $s, $m);
|
|
|
|
$lxdh = $m[2];
|
|
|
|
}
|
|
|
|
return $lxdh;
|
|
|
|
}
|
|
|
|
function u2g($str)
|
|
|
|
{
|
|
|
|
return iconv("utf-8", "gbk//ignore", $str);
|
|
|
|
}
|
|
|
|
function g2u($str)
|
|
|
|
{
|
|
|
|
return iconv("gbk//ignore", "utf-8", $str);
|
|
|
|
}
|
|
|
|
function gto34($num)
|
|
|
|
{
|
|
|
|
$s = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
|
|
$l = strlen($s);
|
|
|
|
$a1 = intval(bcdiv($num, $l));
|
|
|
|
$a2 = bcmod($num, $l);
|
|
|
|
$ss = '';
|
|
|
|
while($a1 > 0) {
|
|
|
|
$ss .= $s{$a2};
|
|
|
|
$num = $a1;
|
|
|
|
$a1 = intval(bcdiv($num, $l));
|
|
|
|
$a2 = bcmod($num, $l);
|
|
|
|
}
|
|
|
|
$ss .= $s{$a2};
|
|
|
|
return $ss;
|
|
|
|
}
|
|
|
|
function gfr34($ss)
|
|
|
|
{
|
|
|
|
$s = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
|
|
|
|
$N = 1;
|
|
|
|
$total = 0;
|
|
|
|
for($i = 0; $i < strlen($ss); $i++) {
|
|
|
|
$a = $ss{$i};
|
|
|
|
$p = strpos($s, $a);
|
|
|
|
if($p === false) return "";
|
|
|
|
$total = bcadd($total, bcmul($p, $N));
|
|
|
|
$N = bcmul($N, strlen($s));
|
|
|
|
}
|
|
|
|
return $total;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ?????????
|
|
|
|
* @param $vStr
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function isCreditNo($vStr)
|
|
|
|
{
|
|
|
|
$vCity = array(
|
|
|
|
'11','12','13','14','15','21','22',
|
|
|
|
'23','31','32','33','34','35','36',
|
|
|
|
'37','41','42','43','44','45','46',
|
|
|
|
'50','51','52','53','54','61','62',
|
|
|
|
'63','64','65','71','81','82','91'
|
|
|
|
);
|
|
|
|
if(strlen($vStr) != 18) return false;
|
|
|
|
if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
|
|
|
|
|
|
|
|
if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
|
|
|
|
|
|
|
|
$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
|
|
|
|
$vLength = strlen($vStr);
|
|
|
|
|
|
|
|
if ($vLength == 18)
|
|
|
|
{
|
|
|
|
$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
|
|
|
|
} else {
|
|
|
|
$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
|
|
|
|
if ($vLength == 18)
|
|
|
|
{
|
|
|
|
$vSum = 0;
|
|
|
|
|
|
|
|
for ($i = 17 ; $i >= 0 ; $i--)
|
|
|
|
{
|
|
|
|
$vSubStr = substr($vStr, 17 - $i, 1);
|
|
|
|
$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
|
|
|
|
}
|
|
|
|
|
|
|
|
if($vSum % 11 != 1) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*function getqrimg($str)
|
|
|
|
{
|
|
|
|
require_once 'include/qrcode/qrlib.php';
|
|
|
|
$d = date("Ym");
|
|
|
|
if(!is_dir("images/qr/{$d}")) mkdir("images/qr/{$d}");
|
|
|
|
$t = "images/qr/{$d}/qr".time().rand().".png";
|
|
|
|
QRcode::png($str, $t, 'L',9 , 6);
|
|
|
|
return $t;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
function getqrimg($str)
|
|
|
|
{
|
|
|
|
require_once 'include/qrcode/qrlib.php';
|
|
|
|
$d = date("Ym");
|
|
|
|
if(!is_dir($_SERVER[APPL_PHYSICAL_PATH]."images/qr/{$d}"))
|
|
|
|
{
|
|
|
|
//mkdir("images/");
|
|
|
|
//mkdir("images/qr");
|
|
|
|
mkdir($_SERVER[APPL_PHYSICAL_PATH]."images/qr/{$d}",0,true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$t = "images/qr/{$d}/qr".time().rand().".png";
|
|
|
|
QRcode::png($str, $_SERVER[APPL_PHYSICAL_PATH].$t, 'L',9 , 6);
|
|
|
|
return $t;
|
|
|
|
}
|
|
|
|
|
|
|
|
function key_enc($enkey, $str, $type = 0)
|
|
|
|
{
|
|
|
|
if(!$str) return '';
|
|
|
|
if($type == 0) {
|
|
|
|
$blocksize = mcrypt_get_block_size ( MCRYPT_3DES, MCRYPT_MODE_ECB );
|
|
|
|
$pad = $blocksize - (strlen ( $str ) % $blocksize);
|
|
|
|
return trim(base64_encode(@mcrypt_ecb(MCRYPT_3DES, $enkey, $str . str_repeat ( chr ( $pad ), $pad ), MCRYPT_ENCRYPT)));
|
|
|
|
}
|
|
|
|
$text = @mcrypt_ecb(MCRYPT_3DES, $enkey, base64_decode($str), MCRYPT_DECRYPT);
|
|
|
|
$pad = ord ( $text {strlen ( $text ) - 1} );
|
|
|
|
if ($pad > strlen ( $text ))
|
|
|
|
return false;
|
|
|
|
if (strspn ( $text, chr ( $pad ), strlen ( $text ) - $pad ) != $pad)
|
|
|
|
return false;
|
|
|
|
if($pad == 0) return rtrim($text);
|
|
|
|
return rtrim(substr ( $text, 0, - 1 * $pad ));
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_kvstr($data) {
|
|
|
|
$s = '';
|
|
|
|
foreach($data as $key => $value) {
|
|
|
|
if($s != '') $s .= '&';
|
|
|
|
$s .= $key."=".$value;
|
|
|
|
}
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
function clear_tags($s) {
|
|
|
|
$s = str_replace("<", "(", $s);
|
|
|
|
$s = str_replace(">", ")", $s);
|
|
|
|
return $s;
|
|
|
|
}
|
|
|
|
function pe($s) {
|
|
|
|
if($_SERVER['REMOTE_ADDR'] == '61.142.240.164') {
|
|
|
|
print_r($s);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 send_sms_auto($phone, $msg)
|
|
|
|
{
|
|
|
|
if(strstr($msg, '验证码')) {
|
|
|
|
if(preg_match("/([^0-9]+|^)([0-9]{5,6})([^0-9]+|$)/", $msg, $m)) {
|
|
|
|
$yzm = $m[2];
|
2024-05-30 10:45:46 +08:00
|
|
|
// send_yzm_atom($phone, $yzm);
|
|
|
|
send_sms_ek($phone, $msg);
|
2024-04-01 15:54:27 +08:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pre = substr($phone, 0, 3);
|
|
|
|
if(in_array($pre, array('189', '180', '133', '153', '181', '199', '177'))) {
|
|
|
|
send_sms($phone, $msg);
|
|
|
|
} else {
|
|
|
|
send_sms_ek($phone, $msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function send_yzm_atom($cellphone, $yzm) {
|
|
|
|
$enkey = 'yumJ594mh8k94Af4';
|
|
|
|
$tpl_code = '99768e18c48c12a8';
|
|
|
|
$params = '{"yzm":"'.$yzm.'"}';
|
|
|
|
|
|
|
|
$cellphone = bin2hex(aes_encrypt($cellphone, $enkey, '', true));
|
|
|
|
$tpl_code = bin2hex(aes_encrypt($tpl_code, $enkey, '', true));
|
|
|
|
$params = bin2hex(aes_encrypt($params, $enkey, '', true));
|
|
|
|
|
|
|
|
$post = array('cellphone' => $cellphone, 'tpl_code' => $tpl_code, 'params' => $params, 'yz' => '1');
|
|
|
|
|
|
|
|
$s = gquery("https://cp.fsecity.com/xz/9e0f2d8926b/txgj/txgj_qy/sd_api/?act=send_sms_tpl", $post);
|
|
|
|
//echo $s;
|
2024-05-30 11:19:56 +08:00
|
|
|
}
|
|
|
|
|
2024-05-30 11:31:32 +08:00
|
|
|
if(!function_exists("send_sms_ek")) {
|
|
|
|
function send_sms_ek($mobile, $msg) {
|
|
|
|
$appid = 'svcXhqBFtbvNS6GUVumSM8k0WarOLiOZ';
|
|
|
|
$appkey = 'ex1JUa3xO3JFXB9k5OqULKYYoJz7A2nV';
|
|
|
|
$msg = '【云中美食】' . $msg;
|
|
|
|
$sign = md5($appid . $mobile . $msg . $appkey);
|
|
|
|
$url = "https://sms.189ek.com/yktsms/send";
|
|
|
|
|
|
|
|
$c = curl_init($url);
|
|
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
|
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
|
|
|
|
curl_setopt($c, CURLOPT_POST, 1);
|
|
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, "appid={$appid}&mobile={$mobile}&msg=" . urlencode($msg) . "&sign={$sign}");
|
|
|
|
curl_setopt($c, CURLOPT_TIMEOUT, 10);
|
|
|
|
curl_exec($c);
|
|
|
|
curl_close($c);
|
|
|
|
}
|
2024-04-01 15:54:27 +08:00
|
|
|
}
|