shopxo/extend/base/Behavior.php

313 lines
6.9 KiB
PHP
Raw Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2019-02-18 13:52:07 +08:00
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace base;
/**
2020-09-23 16:03:14 +08:00
* 行为信息驱动
2018-12-28 18:58:37 +08:00
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:50:41+0800
*/
class Behavior
{
/**
2020-09-23 16:03:14 +08:00
* 上报安装日志
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-09-23
* @desc description
* @param [array] $params [输入参数]
2018-12-28 18:58:37 +08:00
*/
2020-09-23 16:03:14 +08:00
public function ReportInstallLog($params = [])
2018-12-28 18:58:37 +08:00
{
// 数据列表
2020-09-23 16:03:14 +08:00
$data = [
'user' => $this->GetUserCookie(),
'host' => $this->GetUrl('host'),
'server_port' => $this->GetServerPort(),
'server_ip' => $this->GetServerIP(),
'url' => $this->GetUrl('url'),
'request_url' => $this->GetUrl('request'),
'source_url' => $this->GetSourceUrl(),
'client_ip' => $this->GetClientIP(),
'os' => $this->GetOs(),
'browser' => $this->GetBrowser(),
'method' => $this->GetMethod(),
'scheme' => $this->GetScheme(),
'version' => $this->GetHttpVersion(),
'client' => $this->GetClinet(),
'php_os' => PHP_OS,
'php_version' => PHP_VERSION,
'php_sapi_name' => php_sapi_name(),
'client_date' => date('Y-m-d H:i:s'),
'ymd' => date('Ymd'),
'ver' => str_replace('v', '', APPLICATION_VERSION),
];
2018-12-28 18:58:37 +08:00
// 描述信息
2020-09-23 16:03:14 +08:00
if(!empty($params['msg']))
2018-12-28 18:58:37 +08:00
{
2020-09-23 16:03:14 +08:00
$data['msg'] = $params['msg'];
2018-12-28 18:58:37 +08:00
}
// mysql版本
2020-09-23 16:03:14 +08:00
if(!empty($params['mysql_version']))
2018-12-28 18:58:37 +08:00
{
2020-09-23 16:03:14 +08:00
$data['mysql_version'] = $params['mysql_version'];
2018-12-28 18:58:37 +08:00
}
// 上报数据
$url = 'http://report.shopxo.net/install.php';
if(function_exists('curl_init'))
{
2020-09-23 16:03:14 +08:00
CurlPost($url, $data);
2018-12-28 18:58:37 +08:00
} else {
2020-09-23 16:03:14 +08:00
FsockopenPost($url, $data);
2018-12-28 18:58:37 +08:00
}
}
/**
* [GetScheme http类型]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:04:33+0800
*/
2020-09-23 16:03:14 +08:00
public function GetScheme()
2018-12-28 18:58:37 +08:00
{
2020-09-23 16:03:14 +08:00
return strtoupper(__MY_HTTP__);
2018-12-28 18:58:37 +08:00
}
/**
* [GetClinet 客户端]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:04:56+0800
*/
2020-09-23 16:03:14 +08:00
public function GetClinet()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
}
/**
* [GetHttpVersion http版本]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:04:43+0800
*/
2020-09-23 16:03:14 +08:00
public function GetHttpVersion()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['SERVER_PROTOCOL']) ? '' : str_replace(array('HTTP/', 'HTTPS/'), '', $_SERVER['SERVER_PROTOCOL']);
}
/**
* [GetMethod 请求类型]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:04:23+0800
*/
2020-09-23 16:03:14 +08:00
public function GetMethod()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['REQUEST_METHOD']) ? '' : $_SERVER['REQUEST_METHOD'];
}
/**
* [GetOs 用户操作系统]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:02:06+0800
*/
2020-09-23 16:03:14 +08:00
public function GetOs()
2018-12-28 18:58:37 +08:00
{
if(!empty($_SERVER['HTTP_USER_AGENT']))
{
$os = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/win/i', $os))
{
$os = 'Windows';
} elseif (preg_match('/mac/i',$os))
{
$os = 'MAC';
} elseif (preg_match('/linux/i', $os))
{
$os = 'Linux';
} elseif (preg_match('/unix/i', $os))
{
$os = 'Unix';
} elseif (preg_match('/bsd/i', $os))
{
$os = 'BSD';
} elseif (preg_match('/iphone/i', $os))
{
$os = 'iPhone';
} elseif (preg_match('/android/i', $os))
{
$os = 'Android';
} else {
$os = 'Other';
}
return $os;
}
return 'unknown';
}
/**
* [GetBrowser 用户浏览器]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:03:14+0800
*/
2020-09-23 16:03:14 +08:00
public function GetBrowser()
2018-12-28 18:58:37 +08:00
{
if(!empty($_SERVER['HTTP_USER_AGENT']))
{
$br = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE/i', $br))
{
$br = 'MSIE';
} elseif(preg_match('/Firefox/i', $br))
{
$br = 'Firefox';
} elseif(preg_match('/Chrome/i', $br))
{
$br = 'Chrome';
} elseif(preg_match('/Safari/i', $br))
{
$br = 'Safari';
} elseif (preg_match('/Opera/i', $br))
{
$br = 'Opera';
} else {
$br = 'Other';
}
return $br;
}
return 'unknown';
}
/**
* [GetUrl 获取url地址]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:29:03+0800
* @param [string] $type [host:host地址, url:url地址, request:完整url地址]
*/
2020-09-23 16:03:14 +08:00
public function GetUrl($type = 'url')
2018-12-28 18:58:37 +08:00
{
2020-09-23 16:03:14 +08:00
switch($type)
2018-12-28 18:58:37 +08:00
{
2020-09-23 16:03:14 +08:00
// host
case 'host' :
return __MY_HOST__;
break;
2018-12-28 18:58:37 +08:00
2020-09-23 16:03:14 +08:00
// 当前url
case 'url' :
return __MY_URL__;
break;
2018-12-28 18:58:37 +08:00
2020-09-23 16:03:14 +08:00
// 当前url+参数
default :
return __MY_VIEW_URL__;
2018-12-28 18:58:37 +08:00
}
}
/**
* [GetServerIP 获取服务器ip]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:34:24+0800
*/
2020-09-23 16:03:14 +08:00
public function GetServerIP()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['SERVER_ADDR']) ? '' : $_SERVER['SERVER_ADDR'];
}
/**
* [GetServerPort 获取当前web端口]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:35:42+0800
*/
2020-09-23 16:03:14 +08:00
public function GetServerPort()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['SERVER_PORT']) ? 80 : $_SERVER['SERVER_PORT'];
}
/**
* [GetClientIP 获取用户ip]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T16:00:10+0800
* @param [boolean] $long [是否转换成整数]
*/
function GetClientIP($long = false)
{
2020-09-23 16:03:14 +08:00
return GetClientIP($long);
2018-12-28 18:58:37 +08:00
}
/**
* [GetSourceUrl 获取来源url地址]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T15:57:00+0800
*/
2020-09-23 16:03:14 +08:00
public function GetSourceUrl()
2018-12-28 18:58:37 +08:00
{
return empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
}
/**
* [GetUserCookie 获取用户cookieid]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T15:55:12+0800
*/
2020-09-23 16:03:14 +08:00
public function GetUserCookie()
2018-12-28 18:58:37 +08:00
{
if(!empty($_COOKIE['behavior_user_cookie']))
{
return $_COOKIE['behavior_user_cookie'];
}
2018-12-28 18:58:37 +08:00
$user_cookie = $this->GetUserNumberRand();
setcookie('behavior_user_cookie', $user_cookie);
return $user_cookie;
}
/**
* [GetUserNumberRand 生成用户cookie编号]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-04-11T15:56:14+0800
*/
2020-09-23 16:03:14 +08:00
public function GetUserNumberRand()
2018-12-28 18:58:37 +08:00
{
$str = date('YmdHis');
for($i=0; $i<6; $i++) $str .= rand(0, 9);
return $str;
}
}
?>