工会web
This commit is contained in:
201
GonghuiWeb/class/AlipayCore.php
Normal file
201
GonghuiWeb/class/AlipayCore.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/* *
|
||||
* 支付宝接口公用函数
|
||||
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
|
||||
* 版本:3.2
|
||||
* 日期:2011-03-25
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 生成签名结果
|
||||
* @param $sort_para 要签名的数组
|
||||
* @param $key 支付宝交易安全校验码
|
||||
* @param $sign_type 签名类型 默认值:MD5
|
||||
* return 签名结果字符串
|
||||
*/
|
||||
function buildMysign($sort_para,$key,$sign_type = "MD5") {
|
||||
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
$prestr = createLinkstring($sort_para);
|
||||
//把拼接后的字符串再与安全校验码直接连接起来
|
||||
$prestr = $prestr.$key;
|
||||
//把最终的字符串签名,获得签名结果
|
||||
$mysgin = sign($prestr,$sign_type);
|
||||
return $mysgin;
|
||||
}
|
||||
/**
|
||||
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
* @param $para 需要拼接的数组
|
||||
* return 拼接完成以后的字符串
|
||||
*/
|
||||
function createLinkstring($para) {
|
||||
$arg = "";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$arg.=$key."=".$val."&";
|
||||
}
|
||||
//去掉最后一个&字符
|
||||
$arg = substr($arg,0,count($arg)-2);
|
||||
|
||||
//如果存在转义字符,那么去掉转义
|
||||
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
/**
|
||||
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
|
||||
* @param $para 需要拼接的数组
|
||||
* return 拼接完成以后的字符串
|
||||
*/
|
||||
function createLinkstringUrlencode($para) {
|
||||
$arg = "";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$arg.=$key."=".urlencode($val)."&";
|
||||
}
|
||||
//去掉最后一个&字符
|
||||
$arg = substr($arg,0,count($arg)-2);
|
||||
|
||||
//如果存在转义字符,那么去掉转义
|
||||
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
/**
|
||||
* 除去数组中的空值和签名参数
|
||||
* @param $para 签名参数组
|
||||
* return 去掉空值与签名参数后的新签名参数组
|
||||
*/
|
||||
function paraFilter($para) {
|
||||
$para_filter = array();
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
if($key == "sign" || $key == "sign_type" || $val == "")continue;
|
||||
else $para_filter[$key] = $para[$key];
|
||||
}
|
||||
return $para_filter;
|
||||
}
|
||||
/**
|
||||
* 对数组排序
|
||||
* @param $para 排序前的数组
|
||||
* return 排序后的数组
|
||||
*/
|
||||
function argSort($para) {
|
||||
ksort($para);
|
||||
reset($para);
|
||||
return $para;
|
||||
}
|
||||
/**
|
||||
* 签名字符串
|
||||
* @param $prestr 需要签名的字符串
|
||||
* @param $sign_type 签名类型 默认值:MD5
|
||||
* return 签名结果
|
||||
*/
|
||||
function sign($prestr,$sign_type='MD5') {
|
||||
$sign='';
|
||||
if($sign_type == 'MD5') {
|
||||
$sign = md5($prestr);
|
||||
}elseif($sign_type =='DSA') {
|
||||
//DSA 签名方法待后续开发
|
||||
die("DSA 签名方法待后续开发,请先使用MD5签名方式");
|
||||
}else {
|
||||
die("支付宝暂不支持".$sign_type."类型的签名方式");
|
||||
}
|
||||
return $sign;
|
||||
}
|
||||
/**
|
||||
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
|
||||
* 注意:服务器需要开通fopen配置
|
||||
* @param $word 要写入日志里的文本内容 默认值:空值
|
||||
*/
|
||||
function logResult($word='') {
|
||||
$fp = fopen("log.txt","a");
|
||||
flock($fp, LOCK_EX) ;
|
||||
fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程获取数据
|
||||
* 注意:该函数的功能可以用curl来实现和代替。curl需自行编写。
|
||||
* $url 指定URL完整路径地址
|
||||
* @param $input_charset 编码格式。默认值:空值
|
||||
* @param $time_out 超时时间。默认值:60
|
||||
* return 远程输出的数据
|
||||
*/
|
||||
function getHttpResponse($url, $input_charset = '', $time_out = "60") {
|
||||
$urlarr = parse_url($url);
|
||||
$errno = "";
|
||||
$errstr = "";
|
||||
$transports = "";
|
||||
$responseText = "";
|
||||
if($urlarr["scheme"] == "https") {
|
||||
$transports = "ssl://";
|
||||
$urlarr["port"] = "443";
|
||||
} else {
|
||||
$transports = "tcp://";
|
||||
$urlarr["port"] = "80";
|
||||
}
|
||||
$fp=@fsockopen($transports . $urlarr['host'],$urlarr['port'],$errno,$errstr,$time_out);
|
||||
if(!$fp) {
|
||||
die("ERROR: $errno - $errstr<br />\n");
|
||||
} else {
|
||||
if (trim($input_charset) == '') {
|
||||
fputs($fp, "POST ".$urlarr["path"]." HTTP/1.1\r\n");
|
||||
}
|
||||
else {
|
||||
fputs($fp, "POST ".$urlarr["path"].'?_input_charset='.$input_charset." HTTP/1.1\r\n");
|
||||
}
|
||||
fputs($fp, "Host: ".$urlarr["host"]."\r\n");
|
||||
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
|
||||
fputs($fp, "Content-length: ".strlen($urlarr["query"])."\r\n");
|
||||
fputs($fp, "Connection: close\r\n\r\n");
|
||||
fputs($fp, $urlarr["query"] . "\r\n\r\n");
|
||||
while(!feof($fp)) {
|
||||
$responseText .= @fgets($fp, 1024);
|
||||
}
|
||||
fclose($fp);
|
||||
$responseText = trim(stristr($responseText,"\r\n\r\n"),"\r\n");
|
||||
|
||||
return $responseText;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 实现多种字符编码方式
|
||||
* @param $input 需要编码的字符串
|
||||
* @param $_output_charset 输出的编码格式
|
||||
* @param $_input_charset 输入的编码格式
|
||||
* return 编码后的字符串
|
||||
*/
|
||||
function charsetEncode($input,$_output_charset ,$_input_charset) {
|
||||
$output = "";
|
||||
if(!isset($_output_charset) )$_output_charset = $_input_charset;
|
||||
if($_input_charset == $_output_charset || $input ==null ) {
|
||||
$output = $input;
|
||||
} elseif (function_exists("mb_convert_encoding")) {
|
||||
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
|
||||
} elseif(function_exists("iconv")) {
|
||||
$output = iconv($_input_charset,$_output_charset,$input);
|
||||
} else die("sorry, you have no libs support for charset change.");
|
||||
return $output;
|
||||
}
|
||||
/**
|
||||
* 实现多种字符解码方式
|
||||
* @param $input 需要解码的字符串
|
||||
* @param $_output_charset 输出的解码格式
|
||||
* @param $_input_charset 输入的解码格式
|
||||
* return 解码后的字符串
|
||||
*/
|
||||
function charsetDecode($input,$_input_charset ,$_output_charset) {
|
||||
$output = "";
|
||||
if(!isset($_input_charset) )$_input_charset = $_input_charset ;
|
||||
if($_input_charset == $_output_charset || $input ==null ) {
|
||||
$output = $input;
|
||||
} elseif (function_exists("mb_convert_encoding")) {
|
||||
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
|
||||
} elseif(function_exists("iconv")) {
|
||||
$output = iconv($_input_charset,$_output_charset,$input);
|
||||
} else die("sorry, you have no libs support for charset changes.");
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
139
GonghuiWeb/class/AlipayNotify.php
Normal file
139
GonghuiWeb/class/AlipayNotify.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/* *
|
||||
* 类名:AlipayNotify
|
||||
* 功能:支付宝通知处理类
|
||||
* 详细:处理支付宝各接口通知返回
|
||||
* 版本:3.2
|
||||
* 日期:2011-03-25
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考
|
||||
|
||||
*************************注意*************************
|
||||
* 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
|
||||
*/
|
||||
class AlipayNotify {
|
||||
/**
|
||||
* HTTPS形式消息验证地址
|
||||
*/
|
||||
var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
|
||||
/**
|
||||
* HTTP形式消息验证地址
|
||||
*/
|
||||
var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
|
||||
var $aliapy_config;
|
||||
|
||||
function __construct($aliapy_config){
|
||||
$this->aliapy_config = $aliapy_config;
|
||||
}
|
||||
function AlipayNotify($aliapy_config) {
|
||||
$this->__construct($aliapy_config);
|
||||
}
|
||||
/**
|
||||
* 针对notify_url验证消息是否是支付宝发出的合法消息
|
||||
* @return 验证结果
|
||||
*/
|
||||
function verifyNotify(){
|
||||
if(empty($_POST)) {//判断POST来的数组是否为空
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
//生成签名结果
|
||||
$mysign = $this->getMysign($_POST);
|
||||
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
|
||||
$responseTxt = 'true';
|
||||
if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);}
|
||||
|
||||
//写日志记录
|
||||
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:sign=".$_POST["sign"]."&mysign=".$mysign.",";
|
||||
//$log_text = $log_text.createLinkString($_POST);
|
||||
//logResult($log_text);
|
||||
|
||||
|
||||
|
||||
//验证
|
||||
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
|
||||
//mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
|
||||
if (preg_match("/true$/i",$responseTxt) && $mysign == $_POST["sign"]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对return_url验证消息是否是支付宝发出的合法消息
|
||||
* @return 验证结果
|
||||
*/
|
||||
function verifyReturn(){
|
||||
if(empty($_GET)) {//判断POST来的数组是否为空
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
//生成签名结果
|
||||
$mysign = $this->getMysign($_GET);
|
||||
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
|
||||
$responseTxt = 'true';
|
||||
if (! empty($_GET["notify_id"])) {$responseTxt = $this->getResponse($_GET["notify_id"]);}
|
||||
|
||||
//写日志记录
|
||||
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:sign=".$_GET["sign"]."&mysign=".$mysign.",";
|
||||
//$log_text = $log_text.createLinkString($_GET);
|
||||
//logResult($log_text);
|
||||
|
||||
//验证
|
||||
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
|
||||
//mysign与sign不等,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
|
||||
if (preg_match("/true$/i",$responseTxt) && $mysign == $_GET["sign"]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据反馈回来的信息,生成签名结果
|
||||
* @param $para_temp 通知返回来的参数数组
|
||||
* @return 生成的签名结果
|
||||
*/
|
||||
function getMysign($para_temp) {
|
||||
//除去待签名参数数组中的空值和签名参数
|
||||
$para_filter = paraFilter($para_temp);
|
||||
|
||||
//对待签名参数数组排序
|
||||
$para_sort = argSort($para_filter);
|
||||
|
||||
//生成签名结果
|
||||
$mysign = buildMysign($para_sort, trim($this->aliapy_config['key']), strtoupper(trim($this->aliapy_config['sign_type'])));
|
||||
|
||||
return $mysign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程服务器ATN结果,验证返回URL
|
||||
* @param $notify_id 通知校验ID
|
||||
* @return 服务器ATN结果
|
||||
* 验证结果集:
|
||||
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
|
||||
* true 返回正确信息
|
||||
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
|
||||
*/
|
||||
function getResponse($notify_id) {
|
||||
$transport = strtolower(trim($this->aliapy_config['transport']));
|
||||
$partner = trim($this->aliapy_config['partner']);
|
||||
$veryfy_url = '';
|
||||
if($transport == 'https') {
|
||||
$veryfy_url = $this->https_verify_url;
|
||||
}
|
||||
else {
|
||||
$veryfy_url = $this->http_verify_url;
|
||||
}
|
||||
$veryfy_url = $veryfy_url."partner=" . $partner . "¬ify_id=" . $notify_id;
|
||||
$responseTxt = getHttpResponse($veryfy_url);
|
||||
|
||||
return $responseTxt;
|
||||
}
|
||||
}
|
||||
?>
|
||||
90
GonghuiWeb/class/AlipayService.php
Normal file
90
GonghuiWeb/class/AlipayService.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/* *
|
||||
* 类名:AlipayService
|
||||
* 功能:支付宝各接口构造类
|
||||
* 详细:构造支付宝各接口请求参数
|
||||
* 版本:3.2
|
||||
* 日期:2011-03-25
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
class AlipayService {
|
||||
|
||||
var $aliapy_config;
|
||||
/**
|
||||
*支付宝网关地址(新)
|
||||
*/
|
||||
var $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?';
|
||||
|
||||
function __construct($aliapy_config){
|
||||
$this->aliapy_config = $aliapy_config;
|
||||
}
|
||||
function AlipayService($aliapy_config) {
|
||||
$this->__construct($aliapy_config);
|
||||
}
|
||||
/**
|
||||
* 构造担保交易接口
|
||||
* @param $para_temp 请求参数数组
|
||||
* @return 表单提交HTML信息
|
||||
*/
|
||||
function create_partner_trade_by_buyer($para_temp) {
|
||||
//设置按钮名称
|
||||
$button_name = "确认";
|
||||
//生成表单提交HTML文本信息
|
||||
$alipaySubmit = new AlipaySubmit();
|
||||
$html_text = $alipaySubmit->buildForm($para_temp, $this->alipay_gateway_new, "get", $button_name, $this->aliapy_config);
|
||||
|
||||
return $html_text;
|
||||
}
|
||||
/**
|
||||
* 构造确认发货接口
|
||||
* @param $para_temp 请求参数数组
|
||||
* @return 获取支付宝的返回XML处理结果
|
||||
*/
|
||||
function send_goods_confirm_by_platform($para_temp) {
|
||||
|
||||
//获取支付宝的返回XML处理结果
|
||||
$alipaySubmit = new AlipaySubmit();
|
||||
$html_text = $alipaySubmit->sendPostInfo($para_temp, $this->alipay_gateway_new, $this->aliapy_config);
|
||||
|
||||
return $html_text;
|
||||
}
|
||||
/**
|
||||
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
|
||||
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
|
||||
* return 时间戳字符串
|
||||
*/
|
||||
function query_timestamp() {
|
||||
$url = $this->alipay_gateway_new."service=query_timestamp&partner=".trim($this->aliapy_config['partner']);
|
||||
$encrypt_key = "";
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->load($url);
|
||||
$itemEncrypt_key = $doc->getElementsByTagName( "encrypt_key" );
|
||||
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
|
||||
|
||||
return $encrypt_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造支付宝其他接口
|
||||
* @param $para_temp 请求参数数组
|
||||
* @return 表单提交HTML信息/支付宝返回XML处理结果
|
||||
*/
|
||||
function alipay_interface($para_temp) {
|
||||
//获取远程数据/生成表单提交HTML文本信息
|
||||
$alipaySubmit = new AlipaySubmit();
|
||||
$html_text = "";
|
||||
//请根据不同的接口特性,选择一种请求方式
|
||||
//1.构造表单提交HTML数据:($method可赋值为get或post)
|
||||
//$alipaySubmit->buildForm($para_temp, $this->alipay_gateway_new, "get", $button_name, $this->aliapy_config);
|
||||
//2.构造模拟远程HTTP的POST请求,获取支付宝的返回XML处理结果:
|
||||
//注意:若要使用远程HTTP获取数据,必须开通SSL服务,该服务请找到php.ini配置文件设置开启,建议与您的网络管理员联系解决。
|
||||
//$alipaySubmit->sendPostInfo($para_temp, $this->alipay_gateway_new, $this->aliapy_config);
|
||||
|
||||
return $html_text;
|
||||
}
|
||||
}
|
||||
?>
|
||||
101
GonghuiWeb/class/AlipaySubmit.php
Normal file
101
GonghuiWeb/class/AlipaySubmit.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/* *
|
||||
* 类名:AlipaySubmit
|
||||
* 功能:支付宝各接口请求提交类
|
||||
* 详细:构造支付宝各接口表单HTML文本,获取远程HTTP数据
|
||||
* 版本:3.2
|
||||
* 日期:2011-03-25
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
*/
|
||||
class AlipaySubmit {
|
||||
/**
|
||||
* 生成要请求给支付宝的参数数组
|
||||
* @param $para_temp 请求前的参数数组
|
||||
* @param $aliapy_config 基本配置信息数组
|
||||
* @return 要请求的参数数组
|
||||
*/
|
||||
function buildRequestPara($para_temp,$aliapy_config) {
|
||||
//除去待签名参数数组中的空值和签名参数
|
||||
$para_filter = paraFilter($para_temp);
|
||||
|
||||
//对待签名参数数组排序
|
||||
$para_sort = argSort($para_filter);
|
||||
|
||||
//生成签名结果
|
||||
$mysign = buildMysign($para_sort, trim($aliapy_config['key']), strtoupper(trim($aliapy_config['sign_type'])));
|
||||
|
||||
//签名结果与签名方式加入请求提交参数组中
|
||||
$para_sort['sign'] = $mysign;
|
||||
$para_sort['sign_type'] = strtoupper(trim($aliapy_config['sign_type']));
|
||||
|
||||
return $para_sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成要请求给支付宝的参数数组
|
||||
* @param $para_temp 请求前的参数数组
|
||||
* @param $aliapy_config 基本配置信息数组
|
||||
* @return 要请求的参数数组字符串
|
||||
*/
|
||||
function buildRequestParaToString($para_temp,$aliapy_config) {
|
||||
//待请求参数数组
|
||||
$para = $this->buildRequestPara($para_temp,$aliapy_config);
|
||||
|
||||
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode编码
|
||||
$request_data = createLinkstringUrlencode($para);
|
||||
|
||||
return $request_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造提交表单HTML数据
|
||||
* @param $para_temp 请求参数数组
|
||||
* @param $gateway 网关地址
|
||||
* @param $method 提交方式。两个值可选:post、get
|
||||
* @param $button_name 确认按钮显示文字
|
||||
* @return 提交表单HTML文本
|
||||
*/
|
||||
function buildForm($para_temp, $gateway, $method, $button_name, $aliapy_config) {
|
||||
//待请求参数数组
|
||||
$para = $this->buildRequestPara($para_temp,$aliapy_config);
|
||||
|
||||
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$gateway."_input_charset=".trim(strtolower($aliapy_config['input_charset']))."' method='".$method."'>";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
|
||||
}
|
||||
|
||||
//submit按钮控件请不要含有name属性
|
||||
$sHtml = $sHtml."<input type='submit' value='".$button_name."'></form>";
|
||||
|
||||
$sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>";
|
||||
|
||||
return $sHtml;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造模拟远程HTTP的POST请求,获取支付宝的返回XML处理结果
|
||||
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
|
||||
* @param $para_temp 请求参数数组
|
||||
* @param $gateway 网关地址
|
||||
* @param $aliapy_config 基本配置信息数组
|
||||
* @return 支付宝返回XML处理结果
|
||||
*/
|
||||
function sendPostInfo($para_temp, $gateway, $aliapy_config) {
|
||||
$xml_str = '';
|
||||
|
||||
//待请求参数数组字符串
|
||||
$request_data = $this->buildRequestParaToString($para_temp,$aliapy_config);
|
||||
//请求的url完整链接
|
||||
$url = $gateway . $request_data;
|
||||
//远程获取数据
|
||||
$xml_data = getHttpResponse($url,trim(strtolower($aliapy_config['input_charset'])));
|
||||
//解析XML
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadXML($xml_data);
|
||||
|
||||
return $doc;
|
||||
}
|
||||
}
|
||||
?>
|
||||
6283
GonghuiWeb/class/PclZip.php
Normal file
6283
GonghuiWeb/class/PclZip.php
Normal file
File diff suppressed because it is too large
Load Diff
384
GonghuiWeb/class/files.php
Normal file
384
GonghuiWeb/class/files.php
Normal file
@@ -0,0 +1,384 @@
|
||||
<?php
|
||||
class files{
|
||||
function encode($data){
|
||||
if($data!=null){
|
||||
$data=rawurlencode($data);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
function decode($data){
|
||||
if($data!=null){
|
||||
$data=rawurldecode($data);
|
||||
return $data;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function opendir($path,$light=''){
|
||||
if(preg_match('/[\/]$/',$path)==false){
|
||||
$path=$path.'/';
|
||||
}
|
||||
if(!is_dir($path)){
|
||||
return false;
|
||||
}
|
||||
if(($handle=opendir($path))==false){
|
||||
return false;
|
||||
}
|
||||
while($f=readdir($handle)){
|
||||
$f=$path.$f;
|
||||
$fname=$this->typename($f);
|
||||
if(is_array($light)){
|
||||
foreach($light as $value){
|
||||
if($fname==$this->path2name($value)) $fname="<font color=red>".$fname."</font>";
|
||||
}
|
||||
}elseif($light){
|
||||
if($fname==$this->path2name($light)) $fname="<font color=red>".$fname."</font>";
|
||||
}
|
||||
if($f==($path.'.')){
|
||||
$data['.']=realpath($f);
|
||||
}elseif($f==($path.'..')){
|
||||
$data['..']=realpath($f);
|
||||
}elseif(is_dir($f)){
|
||||
$data['dir'][]=array(
|
||||
'path'=>realpath($f),
|
||||
'name'=>$fname,
|
||||
'power'=>$this->power($f),
|
||||
'ftime'=>$this->ftime($f),
|
||||
'etime'=>$this->etime($f)
|
||||
);
|
||||
}elseif(is_file($f)){
|
||||
$data['file'][]=array(
|
||||
'path'=>realpath($f),
|
||||
'name'=>$fname,
|
||||
'size'=>$this->filesize($f),
|
||||
'typeimg'=>$this->typeimg($f),
|
||||
'power'=>$this->power($f),
|
||||
'ftime'=>$this->ftime($f),
|
||||
'etime'=>$this->etime($f)
|
||||
);
|
||||
}else{
|
||||
$data['other'][]=realpath($f);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
function page($array,$pagesize=0,$linkNum=7,$page=1){//分页
|
||||
if(!preg_match('/^[0-9]+$/i',$page) || !$page) $page=1;
|
||||
$content=array();
|
||||
$total=count($array);
|
||||
if(!preg_match('/^[0-9]+$/i',$pagesize) || !$pagesize) $pagesize=$total;
|
||||
if(!$pagesize) $pagesize=30;
|
||||
$maxPage=ceil($total/$pagesize);//最大页码
|
||||
$page=($page>($maxPage)?($maxPage):$page);
|
||||
$start=($page-1)*$pagesize;
|
||||
if($pagesize>$total) $pagesize=$total;
|
||||
for($i=$start;$i<($start+$pagesize);$i++){
|
||||
if($array[$i]) array_push($content,$array[$i]);
|
||||
}
|
||||
$this->start=($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
|
||||
$this->end=($page+round($linkNum/2))<$maxPage ? ($page+round($linkNum/2)) : $maxPage;
|
||||
$this->maxPage=$maxPage;//最大页码
|
||||
$this->pageSize=$pageSize;//每页显示
|
||||
$this->linkNum=$linkNum;//链接显示数
|
||||
$this->totalNum=$total;//总数
|
||||
$this->page=$page;//当前页
|
||||
return $content;
|
||||
}
|
||||
function getpagecs(){ //获取分页参数
|
||||
$myarray = array('Page'=>$this->page,'Start'=>$this->start,'End'=>$this->end,'maxPage'=>$this->maxPage,'pageSize'=>$this->pageSize,'linkNum'=>$this->linkNum,'totalNum'=>$this->totalNum);
|
||||
return $myarray;
|
||||
}
|
||||
function power($path){//获取权限
|
||||
$p=$this->decode($path);
|
||||
if(preg_match('/%/',$p)){
|
||||
return '未知';
|
||||
}else{
|
||||
return substr(sprintf('%o',fileperms($p)),-4);
|
||||
}
|
||||
}
|
||||
function ftime($path){//获取最后访问时间
|
||||
$p=$this->decode($path);
|
||||
if(preg_match('/%/',$p)){
|
||||
return '未知';
|
||||
}else{
|
||||
return $this->times(gmdate("Y-m-d H:i:s",fileatime($p)+8*3600));
|
||||
}
|
||||
}
|
||||
function etime($path){//获取最后修改时间
|
||||
$p=$this->decode($path);
|
||||
if(preg_match('/%/',$p)){
|
||||
return '未知';
|
||||
}else{
|
||||
return $this->times(gmdate("Y-m-d H:i:s",filemtime($p)+8*3600));
|
||||
}
|
||||
}
|
||||
function times($time){
|
||||
if(strtotime($time)>strtotime("today")){
|
||||
return '<font color=red>今天</font> '.date("m-d H:i:s",strtotime($time));
|
||||
}elseif(strtotime($time)>strtotime("-2 day")){
|
||||
return '<font color=#ff6600>昨天</font> '.date("m-d H:i:s",strtotime($time));
|
||||
}elseif(strtotime($time)>strtotime("last week")){
|
||||
return '<font color=green>上周</font> '.date("m-d H:i:s",strtotime($time));
|
||||
}else{
|
||||
return $time;
|
||||
}
|
||||
}
|
||||
function path2name($path){
|
||||
return preg_replace('/^.+[\\\\\\/]/', '', $path);
|
||||
//return basename($path);
|
||||
}
|
||||
function typename($path){//获取名称
|
||||
$c=strrchr($path,'/');
|
||||
if($c){
|
||||
return str_replace("/", "", $c);
|
||||
}
|
||||
}
|
||||
function typeimg($path){//获取文件图标
|
||||
$c=strrchr($path,'.');
|
||||
if($c){
|
||||
$c=strtolower($c);//转换小写
|
||||
if($c=='.txt'){
|
||||
return "txt";
|
||||
}elseif($c=='.rar' || $c=='.zip'){
|
||||
return "rar";
|
||||
}elseif($c=='.js'){
|
||||
return "js";
|
||||
}elseif($c=='.gif' || $c=='.jpg' || $c=='.png' || $c=='.bmp' || $c=='.zip'){
|
||||
return "jpg";
|
||||
}elseif($c=='.css'){
|
||||
return "css";
|
||||
}elseif($c=='.php'){
|
||||
return "php";
|
||||
}elseif($c=='.tpl'){
|
||||
return "tpl";
|
||||
}elseif($c=='.asp'){
|
||||
return "asp";
|
||||
}elseif($c=='.mp3' || $c=='.wmv'){
|
||||
return "mp3";
|
||||
}else{
|
||||
return "da";
|
||||
}
|
||||
}else{
|
||||
return 'da';
|
||||
}
|
||||
}
|
||||
function filesize($path){
|
||||
$size=filesize($path);
|
||||
if($size<=1024) {
|
||||
return $size.'B';
|
||||
}elseif($size<=(1024*1024)){
|
||||
$size=$size/1024;
|
||||
return number_format($size,3).'KB';
|
||||
}elseif($size<=(1024*1024*1024)){
|
||||
$size=$size/1024/1024;
|
||||
return number_format($size,3).'MB';
|
||||
}else{
|
||||
$size=$size/1024/1024/1024;
|
||||
return number_format($size,3).'GB';
|
||||
}
|
||||
}
|
||||
function adddir($name,$path){//创建目录
|
||||
if(preg_match('/^([a-zA-Z0-9_\-\.\x{4e00}-\x{9fa5}]+)$/u',$name)!=false){
|
||||
$paths=iconv("utf-8","gbk",$this->decode($path).'/'.$name);
|
||||
if(!is_dir($paths)){
|
||||
mkdir($paths,0777);
|
||||
}else{
|
||||
$name=$name."_".mt_rand(1,9999999);
|
||||
mkdir($this->decode($path).'/'.$name,0777);
|
||||
}
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
function re_name($name,$path){//重命名
|
||||
if(preg_match('/^([a-zA-Z0-9_\-\.\x{4e00}-\x{9fa5}]+)$/u',$name)!=false) {
|
||||
$path=iconv("utf-8","gbk",$this->decode($path));
|
||||
$name=iconv("utf-8","gbk",$name);
|
||||
if(is_dir($path)){
|
||||
chdir(dirname($path.'/'.$name).'/../');
|
||||
$to=getcwd().'/'.$name;
|
||||
if(is_dir($to)){
|
||||
$to=getcwd().'/'.$name."_".mt_rand(1,9999999);
|
||||
}
|
||||
}else{
|
||||
$to=dirname($path).'/'.$name;
|
||||
if(file_exists($to)){
|
||||
$to=dirname($path).'/'.$name.".".mt_rand(1,9999999);
|
||||
}
|
||||
}
|
||||
if(rename($path,$to)!=false){
|
||||
return $this->decode(dirname($to));
|
||||
}
|
||||
}
|
||||
}
|
||||
function copyDir($source,$destination){
|
||||
$result = true;
|
||||
if(is_dir($source)){
|
||||
if(!is_dir($destination)){
|
||||
mkdir($destination,0777);
|
||||
}else{
|
||||
$destination=$destination."_".mt_rand(1,9999999);
|
||||
mkdir($destination,0777);
|
||||
}
|
||||
$handle = opendir($source);
|
||||
while(($file = readdir($handle)) !== false){
|
||||
if($file != '.' && $file != '..'){
|
||||
$src = $source . DIRECTORY_SEPARATOR . $file;
|
||||
$dtn = $destination . DIRECTORY_SEPARATOR . $file;
|
||||
if(is_dir($src)){
|
||||
$this->copyDir($src, $dtn);
|
||||
}else{
|
||||
if(!copy($src, $dtn)){
|
||||
$result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function filemime($path){
|
||||
if(function_exists('finfo_open')==true){
|
||||
$finfo=finfo_open(FILEINFO_MIME);
|
||||
$mime=finfo_file($finfo,$path);
|
||||
finfo_close($finfo);
|
||||
return $mime;
|
||||
}elseif(function_exists('mime_content_type')==true){
|
||||
return mime_content_type($path);
|
||||
}else{
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
function my_judge_empty_dir($directory){//判断目录是否为空
|
||||
$handle = opendir($directory);
|
||||
while(($file = readdir($handle)) !== false){
|
||||
if ($file != "." && $file != ".."){
|
||||
closedir($handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
return true;
|
||||
}
|
||||
function removeDir($dirName){//删除目录
|
||||
if(!is_dir($dirName)) {
|
||||
return false;
|
||||
}
|
||||
$handle=opendir($dirName);
|
||||
while(($file=readdir($handle))!==false){
|
||||
if($file!="."&&$file!=".."){
|
||||
$dir=$dirName."/".$file;
|
||||
is_dir($dir) ? $this->removeDir($dir) : unlink($dir);
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
return rmdir($dirName) ;
|
||||
}
|
||||
function removeFile($path){//删除文件
|
||||
if(file_exists($path)==true){
|
||||
unlink($path);
|
||||
}
|
||||
if(file_exists($path)==false){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function is_utf8($word){//判断是否UTF8编码文件
|
||||
if(preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true){
|
||||
return 'utf-8';
|
||||
}else{
|
||||
return 'gb2312';
|
||||
}
|
||||
}
|
||||
function save($path,$content,$charset=''){//保存文件
|
||||
if($charset=='utf-8'){
|
||||
$content=iconv("gbk","utf-8",$content);
|
||||
}
|
||||
$f=fopen($path,"wb");
|
||||
fputs($f, $content);
|
||||
fclose($f);
|
||||
return true;
|
||||
}
|
||||
// function view($path,$size){
|
||||
// if(filesize($path)==0){
|
||||
// return false;
|
||||
// }
|
||||
// if(($data=file_get_contents($path))==false){
|
||||
// return false;
|
||||
// }
|
||||
// if(function_exists('iconv_substr')==true){
|
||||
// $total_page=iconv_strlen($data,'utf-8')/$size;
|
||||
// if($total_page<=1) {
|
||||
// $total_page=1;
|
||||
// }
|
||||
// $i=1;
|
||||
// while($i<($total_page+1)){
|
||||
// $idata[]=iconv_substr($data,$i*$size-$size,$size,'utf-8');
|
||||
// $i++;
|
||||
// }
|
||||
// return $idata;
|
||||
// }else{
|
||||
// return $data;
|
||||
// }
|
||||
// }
|
||||
|
||||
function readata($path){//读取文件
|
||||
if(($data=file_get_contents($path))==false){
|
||||
return $data=null;
|
||||
}else{
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
function urlupload($path,$furl){//上传远程文件
|
||||
if(function_exists('curl_init')){
|
||||
$ch=curl_init();
|
||||
if(($fp=fopen($path,'w'))==false){
|
||||
return false;
|
||||
}
|
||||
curl_setopt($ch,CURLOPT_URL,$furl);
|
||||
curl_setopt($ch,CURLOPT_FILE,$fp);
|
||||
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}else{
|
||||
$fp=fopen($path,'w');
|
||||
if(!$fp) return false;
|
||||
$fp2=fopen($furl,'r');
|
||||
if(!$fp2) return false;
|
||||
while(!feof($fp2)) {
|
||||
fwrite($fp,fread($fp2,8192));
|
||||
}
|
||||
fclose($fp2);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function is_url($str){
|
||||
return preg_match ('/^(http|ftp|https|ftps):\/\/([a-z0-9\-_]+\.)+[a-z]{2,5}/i',$str);
|
||||
}
|
||||
function setting($url,$p){
|
||||
if($data=$this->readata($url)){
|
||||
$data=str_replace(array(' ','$','<?php','?>',"CONFIG['".strtoupper($p)."']=array("),'',$data);
|
||||
$data=explode(chr(10),$data);
|
||||
foreach($data as $values){
|
||||
if(preg_match("/define+/",$values)){
|
||||
$datb="1|".str_replace(array('//',',','define','(',')',';','"','\''),array('|','|'),$values);
|
||||
if($this->is_utf8($datb)=='gb2312') $datb=$datb;
|
||||
$info[]=explode('|',$datb);
|
||||
}elseif(preg_match("/=>+/",$values)){
|
||||
$datb="0|".str_replace(array('//','=>','$',';',',','"','\''),array('|','|'),$values);
|
||||
if($this->is_utf8($datb)=='gb2312') $datb=$datb;
|
||||
$info[]=explode('|',$datb);
|
||||
}
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
463
GonghuiWeb/class/myConn.php
Normal file
463
GonghuiWeb/class/myConn.php
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
class myConn extends myInc{
|
||||
var $error_log = [];
|
||||
var $query_id;
|
||||
var $num_rows;
|
||||
function __construct($connname=''){ //初始化操作
|
||||
$this->connname=$connname;
|
||||
}
|
||||
function query($sql){
|
||||
$stmt = sqlsrv_query($this->link, $sql);
|
||||
if($stmt === false) {
|
||||
$this->error_log[] = sqlsrv_errors();
|
||||
}else{
|
||||
$this->query_id = $stmt;
|
||||
}
|
||||
}
|
||||
function fetch_all($sql){
|
||||
$this->query($sql);
|
||||
$data = [];
|
||||
while($row = @sqlsrv_fetch_array($this->query_id,SQLSRV_FETCH_ASSOC)) {
|
||||
$data[] = $row;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
function fetch_one($sql){
|
||||
$this->query($sql);
|
||||
return sqlsrv_fetch_array($this->query_id,SQLSRV_FETCH_ASSOC);
|
||||
}
|
||||
function fetch_abc($sql){
|
||||
$count=$this->fetch_one($sql);
|
||||
return current($count);
|
||||
}
|
||||
function affectedRows() {
|
||||
return ($this->query_id) ? @sqlsrv_fetch_row($this->query_id) : false;
|
||||
}
|
||||
function update($table,$field,$where,$conn=''){//修改数据库
|
||||
if($conn) $this->links($conn);
|
||||
if(is_array($field)){
|
||||
foreach ($field as $key => $value){
|
||||
$sqlud.=$key."='".$value."',";
|
||||
}
|
||||
$sql="UPDATE $table SET ".substr($sqlud,0,-1)." WHERE $where ";
|
||||
}else{
|
||||
$sql="UPDATE $table SET $field WHERE $where ";
|
||||
}
|
||||
return $this->query($sql);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function insert($table,$field,$date='',$conn=''){//添加数据库 $date 为空, $field为数组添加
|
||||
if($conn) $this->links($conn);
|
||||
if($date){
|
||||
$sql="INSERT INTO $table ($field) VALUES ($date)";
|
||||
}else{
|
||||
foreach($field as $key => $value){
|
||||
$sqlfield.= $key.",";
|
||||
$sqlvalue.= "'".$value."',";
|
||||
}
|
||||
$sql="INSERT INTO $table (".substr($sqlfield,0,-1).") VALUES (".substr($sqlvalue,0,-1).")";
|
||||
}
|
||||
//echo $sql;
|
||||
return $this->query($sql);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function deldate($table,$where,$conn=''){//删除数据库
|
||||
if($conn) $this->links($conn);
|
||||
$sql="DELETE FROM ".$table." WHERE ".$where." ";
|
||||
$rs=$this->query($sql);
|
||||
return sqlsrv_query($rs);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
//分页 注意一定要 order by
|
||||
//public function page($sql,$pkey,$table,$order='asc',$pageSize=10,$linkNum=7,$page=1,$conn=''){
|
||||
public function page($info){
|
||||
if(!$info['sql'] || !$info['key'] || !$info['table']){
|
||||
return '';
|
||||
}
|
||||
if($info['conn']) $this->links($info['conn']);
|
||||
$info['page'] = is_numeric($info['page']) ? $info['page'] : 1;
|
||||
$info['pageSize'] = is_numeric($info['pageSize']) ? $info['pageSize'] : 10;
|
||||
$info['linkNum'] = is_numeric($info['linkNum']) ? $info['linkNum'] : 7;
|
||||
if(!$info['count']){
|
||||
$info['count'] = "select count(*) from (".str_replace(strrchr($info['sql'],"order"),"",$info['sql']).") tmptable";
|
||||
}
|
||||
$totalNum = $this->fetch_abc($info['count']);//总数
|
||||
$maxPage = (int)ceil($totalNum/$info['pageSize']);//总页码
|
||||
$info['page'] = $info['page']>$maxPage ? $maxPage : $info['page'];
|
||||
$num = ($info['page']-1)*$info['pageSize'];
|
||||
$num = $num<0 ? 0 : $num;
|
||||
//echo $info['count']."<br><br><br>".$totalNum."<br>".$num."<br><br>";
|
||||
$sql=str_replace("select ","select top ".$info['pageSize']." ",$info['sql']);
|
||||
if(strstr($sql,' where ')){
|
||||
if(strstr(strtolower($sql),' left join ')){
|
||||
$sql=str_replace(" where "," where a.".$info['key']." not in(select top ".$num." ".$info['key']." from ".$info['table']." ".$info['where']." order by ".$info['order'].") and ",$sql);
|
||||
}else{
|
||||
$sql=str_replace(" where "," where ".$info['key']." not in(select top ".$num." ".$info['key']." from ".$info['table']." ".$info['where.']." order by ".$info['order'].") and ",$sql);
|
||||
}
|
||||
}else{
|
||||
if(strstr(strtolower($sql),' left join ')){
|
||||
if(strstr($sql,' group by ')){
|
||||
$sql=str_replace(" group by "," where a.".$info['key']." not in(select top ".$num." ".$info['key']." from ".$info['table']." order by ".$info['order'].") group by ",$sql);
|
||||
}else{
|
||||
$sql=str_replace(" order by "," where a.".$info['key']." not in(select top ".$num." ".$info['key']." from ".$info['table']." order by ".$info['order'].") order by ",$sql);
|
||||
}
|
||||
}else{
|
||||
$sql=str_replace(" order "," where ".$info['key']." not in(select top ".$num." ".$info['key']." from ".$info['table']." order by ".$info['order'].") order ",$sql);
|
||||
}
|
||||
}
|
||||
//echo $sql."<br><br><br>";
|
||||
$data = $this->fetch_all($sql);
|
||||
return ['data'=>$data,'page'=>[
|
||||
"page"=>$info['page'],
|
||||
"start"=>($info['page']-round($info['linkNum']/2))>0 ? ($info['page']-round($info['linkNum']/2)) : "1",
|
||||
"end"=>($info['page']+round($info['linkNum']/2))<$maxPage ? ($info['page']+round($info['linkNum']/2)) : $maxPage,
|
||||
"maxPage"=>$maxPage,
|
||||
"pageSize"=>$info['pageSize'], //每页显示
|
||||
"linkNum"=>$info['linkNum'], //链接显示数
|
||||
"totalNum"=>$totalNum //总数
|
||||
]];
|
||||
if($conn) $this->close();
|
||||
}
|
||||
// 字符串截取函数
|
||||
function str_substr($start, $end, $str){
|
||||
$temp = explode($start, $str, 2);
|
||||
$content = explode($end, $temp[1], 2);
|
||||
return $content[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function getfetch($rs,$rr=''){
|
||||
if($rr=='assoc'){
|
||||
return @mssql_fetch_assoc($rs);
|
||||
}elseif($rr=='row'){
|
||||
return @mssql_fetch_row($rs);
|
||||
}else{
|
||||
return @mssql_fetch_array($rs);
|
||||
}
|
||||
}
|
||||
function rscount($rs){ //获取rs总数
|
||||
return mssql_num_rows($rs);
|
||||
}
|
||||
|
||||
function getcount($sql,$hit=0,$conn=''){ //获取总数
|
||||
if($conn) $this->links($conn);
|
||||
return @mssql_num_rows($this->query($sql))+$hit;
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function getcounts($field,$table,$where,$hit=0,$conn=''){ //获取字段总和数
|
||||
if($conn) $this->links($conn);
|
||||
$rs=$this->query("select sum($field) from $table where $where");
|
||||
$row=$this->getfetch($rs);
|
||||
return $row[0]+$hit;
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function getdy($field,$table,$where,$order='',$rr='',$conn=''){//一般调用
|
||||
if($conn) $this->links($conn);//连接数据库
|
||||
$sql="select $field from $table ";
|
||||
if($where){ $sql.="WHERE $where "; }
|
||||
if($order){ $sql.=" order by $order "; }
|
||||
$rs=$this->query($sql);
|
||||
$row=$this->getfetch($rs,$rr);
|
||||
if(preg_match('/[,*]/i',$field)){
|
||||
return $row;
|
||||
}else{
|
||||
return $row[0];
|
||||
}
|
||||
unset($sql,$rs,$row);
|
||||
if($conn) $this->close();//关闭数据库
|
||||
}
|
||||
function getloop($field,$table,$where,$order='',$num=0,$rr='',$conn=''){//一般循环调用
|
||||
if($conn) $this->links($conn);
|
||||
$sql="select $field from $table ";
|
||||
if($where){ $sql.=" WHERE $where "; }
|
||||
if($order){ $sql.=" order by $order "; }
|
||||
$rs=$this->query($sql);
|
||||
$rot=array();
|
||||
if(!$num){ $num=$this->rscount($rs);}
|
||||
for($p=0;$p<$num;$p++){
|
||||
$row=$this->getfetch($rs,$rr);
|
||||
if($row) $rot[]=$row;
|
||||
}
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
|
||||
function getloops($sql,$conn=''){//一般循环调用
|
||||
if($conn) $this->links($conn);
|
||||
$rs=$this->query($sql);
|
||||
$rot=array();
|
||||
if(!$num){ $num=$this->rscount($rs);}
|
||||
for($p=0;$p<$num;$p++){
|
||||
$row=$this->getfetch($rs,$rr);
|
||||
if($row) $rot[]=$row;
|
||||
}
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function getgl($gg,$str){//数组过滤
|
||||
$strs=explode(',',$str);
|
||||
foreach($strs as $value){
|
||||
unset($gg[$value]);
|
||||
}
|
||||
return $gg;
|
||||
}
|
||||
function getxz($str,$x,$d=0){//字符输入限制
|
||||
$s = (strlen($str)+mb_strlen($str,'utf8'))/2;
|
||||
if($d){
|
||||
if($s>=$x && $s<=$d) return $str;
|
||||
}else{
|
||||
if($s>=$x) return $str;
|
||||
}
|
||||
}
|
||||
//全局函数 $ts 特殊转换 | 0=特殊变量 1=num user az tel mail 2=字符限制小 3字符限制最大 4=1小写2大写 5=1编码 2编码
|
||||
//$post=$myConn->getpost($_POST,"a|user,b|0|3|12|2|gbk|utf-8,c|0|0|0|2");
|
||||
//当 a 为数组时不起作用 只能1级特殊转换
|
||||
function getpost($str,$ts='',$key=''){
|
||||
if(is_array($str)){
|
||||
foreach($str as $key => $val){
|
||||
$str[$key] = $this->getpost($val,$ts,$key);
|
||||
}
|
||||
}else{
|
||||
$str=trim($str);
|
||||
if($ts && $key){//解决 $key 二级数组问题
|
||||
if(is_array($ts)){
|
||||
$i=0;
|
||||
foreach($ts as $keys => $vals){
|
||||
if($i) $tss.=",";
|
||||
$tss.=$keys."|".$vals;
|
||||
$i++;
|
||||
}
|
||||
$ts=$tss;
|
||||
}
|
||||
$tsa=explode(",",$ts);
|
||||
for($i=0;$i<count($tsa);$i++){
|
||||
$tsb=explode("|",$tsa[$i]);
|
||||
$ts_name=$tsb[0];//需要转换的特殊变量
|
||||
if($key==$ts_name){
|
||||
$ts_type=$tsb[1];//转换类型 num user az tel mail
|
||||
$ts_small=$tsb[2];//最小字符限制
|
||||
$ts_big=$tsb[3];//最大字符限制
|
||||
$ts_size=$tsb[4];//大小写转换 1 小写 2大写
|
||||
$ts_bma=$tsb[5];//编码转换 gbk
|
||||
$ts_bmb=$tsb[6];//编码转换 utf-8
|
||||
if($ts_bma && $ts_bmb){//编码转换
|
||||
$str=iconv($ts_bma,$ts_bmb,$str);
|
||||
}
|
||||
if($ts_type=='num' || $ts_type==1){//判断是否数字
|
||||
if(!preg_match('/^[0-9]+$/i',$str)) $str=0;
|
||||
}elseif($ts_type=='user' || $ts_type==2){//用户名判断
|
||||
if(!preg_match('/^[0-9a-z_-]+$/i',$str)) $str=0;
|
||||
}elseif($ts_type=='tel' || $ts_type==3){//电话判断
|
||||
if(!preg_match('/^[0-9+-]+$/i',$str)) $str=0;
|
||||
}elseif($ts_type=='mail' || $ts_type==5){//邮箱判断
|
||||
if(!preg_match("/^[a-z0-9\._-]{1,}@[a-z0-9-]{1,}\.[a-z\.]{1,}$/i",$str)) $str=0;
|
||||
}elseif($ts_type=='az' || $ts_type==4){//字母过滤
|
||||
if(!preg_match('/^[a-z]+$/i',$str)) $str=0;
|
||||
}else{//文本过滤
|
||||
$str=$this->getre($str);
|
||||
}
|
||||
if($ts_small){//字符限制
|
||||
$str=$this->getxz($str,$ts_small,$ts_big);
|
||||
}
|
||||
if($ts_size==1){//大小写转换
|
||||
$str=strtolower($str);
|
||||
}elseif($ts_size==2){
|
||||
$str=strtoupper($str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$str=$this->getre($str);
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
function getarray($str,$b='|'){//数组转换 $str 为数组 $b=| 为 $str="a|b|c";
|
||||
if(is_array($str)){
|
||||
$i=0;
|
||||
$b=iconv('gbk','utf-8',$b);
|
||||
foreach($str as $key=>$val){
|
||||
if($i) $string.=$b;
|
||||
$string.=$val;
|
||||
$i++;
|
||||
}
|
||||
return $string;
|
||||
}else{
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
function getre($str){ //提交字符过滤
|
||||
$str=str_replace(";", ";", $str);
|
||||
$str=str_replace("<", "<", $str);
|
||||
$str=str_replace(">", ">", $str);
|
||||
$str=str_replace("\"", """, $str);
|
||||
$str=str_replace("'", "′", $str);
|
||||
$str=str_replace("\\", "", $str);
|
||||
return $str;
|
||||
}
|
||||
function getbm($str,$ba="gbk",$bb="utf-8"){//编码转换
|
||||
return iconv($ba,$bb,$str);
|
||||
}
|
||||
function getip(){ //IP
|
||||
static $realip;
|
||||
if (isset($_SERVER)){
|
||||
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
|
||||
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
|
||||
}else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
|
||||
$realip = $_SERVER["HTTP_CLIENT_IP"];
|
||||
}else{
|
||||
$realip = $_SERVER["REMOTE_ADDR"];
|
||||
}
|
||||
} else {
|
||||
if(getenv("HTTP_X_FORWARDED_FOR")){
|
||||
$realip = getenv("HTTP_X_FORWARDED_FOR");
|
||||
}else if (getenv("HTTP_CLIENT_IP")) {
|
||||
$realip = getenv("HTTP_CLIENT_IP");
|
||||
}else{
|
||||
$realip = getenv("REMOTE_ADDR");
|
||||
}
|
||||
}
|
||||
return $realip;
|
||||
}
|
||||
function treat($original,$history){//当原数组的值为空,历史数据值填补原数组
|
||||
foreach($original as $key=>$val){
|
||||
if($val || $val=='0'){
|
||||
$array[$key]=$val;
|
||||
}else{
|
||||
$array[$key]=$history[$key];
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
function randmm($len){//随机数产生
|
||||
$srcstr="0123456789";
|
||||
mt_srand();
|
||||
$strs="";
|
||||
for($i=0;$i<$len;$i++){
|
||||
$strs.=$srcstr[mt_rand(0,9)];
|
||||
}
|
||||
return $strs;
|
||||
}
|
||||
function randhz($len,$size=0){ //随机混杂生产
|
||||
$srcstr="abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
mt_srand();
|
||||
$strs="";
|
||||
for($i=0;$i<$len;$i++){
|
||||
$strs.=$srcstr[mt_rand(0,35)];
|
||||
}
|
||||
if($size){
|
||||
return strtoupper($strs);
|
||||
}else{
|
||||
return $strs;
|
||||
}
|
||||
}
|
||||
function fileHz($a){//获取文件后缀
|
||||
$c=strrchr($a,'.');
|
||||
if($c){
|
||||
return strtolower($c);//转换小写
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
function createFolder($path) {//创建多级文件夹
|
||||
if (!file_exists($path)) {
|
||||
$this->createFolder(dirname($path));
|
||||
mkdir($path, 0777);
|
||||
}
|
||||
}
|
||||
function filesize($size,$s=2,$h=0){
|
||||
if($h) $size=$size*$h;
|
||||
if($size<=1024) {
|
||||
return $size.'B';
|
||||
}elseif($size<=(1024*1024)){
|
||||
$size=$size/1024;
|
||||
return number_format($size,$s).'KB';
|
||||
}elseif($size<=(1024*1024*1024)){
|
||||
$size=$size/1024/1024;
|
||||
return number_format($size,$s).'MB';
|
||||
}else{
|
||||
$size=$size/1024/1024/1024;
|
||||
return number_format($size,$s).'GB';
|
||||
}
|
||||
}
|
||||
function array_sort($arr,$keys,$type='desc'){ //二维数组重新排序
|
||||
$keysvalue = $new_array = array();
|
||||
foreach ($arr as $k=>$v){
|
||||
$keysvalue[$k] = $v[$keys];
|
||||
}
|
||||
if($type == 'asc'){
|
||||
asort($keysvalue);
|
||||
}else{
|
||||
arsort($keysvalue);
|
||||
}
|
||||
reset($keysvalue);
|
||||
$i=0;
|
||||
foreach ($keysvalue as $k=>$v){
|
||||
$new_array[$i++] = $arr[$k];
|
||||
}
|
||||
return $new_array;
|
||||
}
|
||||
function is_utf8($word){//判断是否UTF8编码文件
|
||||
if(preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true){
|
||||
return 'utf-8';
|
||||
}else{
|
||||
return 'gb2312';
|
||||
}
|
||||
}
|
||||
|
||||
function file_get_nr($url){
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
return curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
function link_so(){
|
||||
$flag = 0;
|
||||
$tmp = $_SERVER['HTTP_USER_AGENT'];
|
||||
if(strpos($tmp, 'Googlebot') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Baiduspider') >0){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'msnbot') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Sosospider') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'fast-webcrawler') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Gaisbot') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'ia_archiver') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'altavista') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'lycos_spider') !== false){
|
||||
$flag = 1;
|
||||
} else if(strpos($tmp, 'Inktomi slurp') !== false){
|
||||
$flag = 1;
|
||||
}
|
||||
return $flag;
|
||||
}
|
||||
|
||||
|
||||
function close(){
|
||||
return sqlsrv_close($this->link);
|
||||
}
|
||||
function __destruct(){
|
||||
}
|
||||
}
|
||||
?>
|
||||
31
GonghuiWeb/class/myInc.php
Normal file
31
GonghuiWeb/class/myInc.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
class myInc {
|
||||
function links($web_conn=''){
|
||||
if($web_conn=="agent"){//代理后台
|
||||
$hostname="47.100.47.128";
|
||||
$dbuser="sa";
|
||||
$dbpasswd="A4b9p3cbt0b6e*!#ypw";
|
||||
$dbname="QPPlatformManagerDB";
|
||||
}elseif($web_conn=="info"){
|
||||
$hostname="47.100.47.128";
|
||||
$dbuser="sa";
|
||||
$dbpasswd="A4b9p3cbt0b6e*!#ypw";
|
||||
$dbname="QPTreasureDB";
|
||||
}elseif($web_conn=="old"){
|
||||
$hostname="106.15.35.78";
|
||||
$dbuser="sa";
|
||||
$dbpasswd="A4b9p3cbt0b6e*!#ypw";
|
||||
$dbname="QPAccountsDB";
|
||||
}else{
|
||||
$hostname="47.100.47.128";
|
||||
$dbuser="sa";
|
||||
$dbpasswd="A4b9p3cbt0b6e*!#ypw";
|
||||
$dbname="QPAccountsDB";
|
||||
}
|
||||
$this->link=sqlsrv_connect($hostname,["UID"=>$dbuser, "PWD"=>$dbpasswd, "Database"=>$dbname]) or die("数据库用户密码错误!");
|
||||
return $this->link;
|
||||
}
|
||||
function __destruct(){
|
||||
}
|
||||
}
|
||||
?>
|
||||
66
GonghuiWeb/class/myPage.php
Normal file
66
GonghuiWeb/class/myPage.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
//通用分页类
|
||||
class myPage extends myConn{
|
||||
function getpage($field,$table,$where,$order='',$pageSize=10,$linkNum=7,$page=1,$conn=''){
|
||||
if($conn) $this->links($conn);
|
||||
if(!preg_match('/^[0-9]+$/i',$page) || !$page) $page=1;
|
||||
|
||||
$sql="select $field from $table ";
|
||||
if($where){ $sql.=" WHERE $where "; }
|
||||
if($order){ $sql.=" order by $order "; }
|
||||
$totalNum=$this->getcount($sql);//总数
|
||||
$rs=$this->query($sql);
|
||||
$maxPage = (int)ceil($totalNum/$pageSize); //得到最大页码数 $maxPage
|
||||
if((int)$page>$maxPage) $page=$maxPage;
|
||||
if(mssql_data_seek($rs,($page-1)*$pageSize)){
|
||||
for($p=0;$p<$pageSize;$p++){
|
||||
$row=$this->getfetch($rs);
|
||||
$Snum=$totalNum-$p-($pageSize*$page)+$pageSize;//序列号
|
||||
if($row) $rot[]=$row+array("Snum"=>$Snum);
|
||||
}
|
||||
}
|
||||
$this->start=($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
|
||||
$this->end=($page+round($linkNum/2))<$maxPage ? ($page+round($linkNum/2)) : $maxPage;
|
||||
$this->maxPage=$maxPage;//最大页码
|
||||
$this->pageSize=$pageSize;//每页显示
|
||||
$this->linkNum=$linkNum;//链接显示数
|
||||
$this->totalNum=$totalNum;//总数
|
||||
$this->page=$page;//当前页
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
|
||||
function getpages($sql,$pageSize=10,$linkNum=7,$page=1,$conn=''){
|
||||
if($conn) $this->links($conn);
|
||||
if(!preg_match('/^[0-9]+$/i',$page) || !$page) $page=1;
|
||||
$totalNum=$this->getcount($sql);//总数
|
||||
$rs=$this->query($sql);
|
||||
$maxPage = (int)ceil($totalNum/$pageSize); //得到最大页码数 $maxPage
|
||||
if((int)$page>$maxPage) $page=$maxPage;
|
||||
if(mssql_data_seek($rs,($page-1)*$pageSize)){
|
||||
for($p=0;$p<$pageSize;$p++){
|
||||
$row=$this->getfetch($rs);
|
||||
$Snum=$totalNum-$p-($pageSize*$page)+$pageSize;//序列号
|
||||
if($row) $rot[]=$row+array("Snum"=>$Snum);
|
||||
}
|
||||
}
|
||||
$this->start=($page-round($linkNum/2))>0 ? ($page-round($linkNum/2)) : "1";
|
||||
$this->end=($page+round($linkNum/2))<$maxPage ? ($page+round($linkNum/2)) : $maxPage;
|
||||
$this->maxPage=$maxPage;//最大页码
|
||||
$this->pageSize=$pageSize;//每页显示
|
||||
$this->linkNum=$linkNum;//链接显示数
|
||||
$this->totalNum=$totalNum;//总数
|
||||
$this->page=$page;//当前页
|
||||
return $rot;
|
||||
unset($sql,$rs,$row,$rot);
|
||||
if($conn) $this->close();
|
||||
}
|
||||
function getpagecs(){ //获取分页参数
|
||||
$myarray = array('Page'=>$this->page,'Start'=>$this->start,'End'=>$this->end,'maxPage'=>$this->maxPage,'pageSize'=>$this->pageSize,'linkNum'=>$this->linkNum,'totalNum'=>$this->totalNum);
|
||||
return $myarray;
|
||||
}
|
||||
function __destruct(){//释放类
|
||||
}
|
||||
}
|
||||
?>
|
||||
56
GonghuiWeb/class/yuwen.php
Normal file
56
GonghuiWeb/class/yuwen.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
class yuwen extends myPage{
|
||||
function __construct($connname=''){ //初始化操作
|
||||
$this->connname=$connname;
|
||||
}
|
||||
function yw($yw,$gid,$wid){
|
||||
for($d=1;$d<7;$d++){
|
||||
foreach($yw as $aid){
|
||||
$yws[$aid][title]=$this->getdy('title',TABLE."class","id='".$aid."'");
|
||||
$yws[$aid][]=$this->getdy("id,title,titlecolor",TABLE."content","gid=".$gid." and weekid='".$wid."' and dayid='".$d."' and lms='".$aid."'");
|
||||
}
|
||||
}
|
||||
return $yws;
|
||||
}
|
||||
/* $out_trade_no 订单
|
||||
$trade_no 支付宝交易号
|
||||
$total 价格
|
||||
$typeid=1 在线付款没有发货 2买家没有确认 3其他状态请检查 8网上支付成功 0其他手工支付成功
|
||||
$buyj 辅导站提成 新版去掉!!!
|
||||
*/
|
||||
function pays($out_trade_no,$trade_no,$total,$typeid='3',$buyj='0'){
|
||||
$save=array('order'=>$trade_no,'typeid'=>$typeid);
|
||||
$this->insert(TABLE."buy",$save);
|
||||
$data=$this->getdy("*",TABLE."buy","orders='$trade_no'");
|
||||
if($data){//修改数据
|
||||
$this->update(TABLE."buy","typeid='".$typeid."'","orders='$trade_no'");
|
||||
}else{//添加数据
|
||||
$da=explode('|',$out_trade_no);
|
||||
$user=$this->getdy("*",TABLE."member","username='".$da['1']."'");
|
||||
$save=array(
|
||||
'uid'=>$user['id'],
|
||||
'typeid'=>$typeid,
|
||||
'orders'=>$trade_no,
|
||||
'username'=>$da[1],
|
||||
'province'=>$user['province'],
|
||||
'school'=>$user['school'],
|
||||
'gid'=>$da[0],
|
||||
'cash'=>intval($total),
|
||||
'money'=>intval($total),
|
||||
'buyj'=>$buyj,
|
||||
'addtime'=>time(),
|
||||
);
|
||||
$this->insert(TABLE."buy",$save);
|
||||
//加入新
|
||||
if($user['buy']){
|
||||
$buy=$user['buy'].$da[0]."|".intval($da[0]+1)."|";
|
||||
}else{
|
||||
$buy="|".$da[0]."|".intval($da[0]+1)."|";
|
||||
}
|
||||
$this->update(TABLE."member","buy='".$buy."'","username='".$da['1']."'");
|
||||
}
|
||||
}
|
||||
function __destruct(){//释放类
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user