96 lines
3.8 KiB
PHP
96 lines
3.8 KiB
PHP
<?php
|
|
if (!function_exists('ds')) {
|
|
function ds($data, $exit = false)
|
|
{
|
|
exit(json_encode([
|
|
'code' => 19980617,
|
|
'msg' => '测试返回',
|
|
'data' => $data
|
|
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
|
|
));
|
|
}
|
|
}
|
|
if (!function_exists('ase_encode')) {
|
|
function ase_encode($data)
|
|
{
|
|
// 获取随机字符串30个
|
|
$random = '';
|
|
for ($i = 0; $i < 30; $i++) {
|
|
$random .= chr(mt_rand(32, 126));
|
|
}
|
|
return base64_encode($random. base64_encode($data));
|
|
}
|
|
}
|
|
if (!function_exists('ase_decode')) {
|
|
function ase_decode($data)
|
|
{
|
|
return base64_decode(substr(base64_decode($data), 30));
|
|
}
|
|
}
|
|
|
|
// 获取用户设备类型
|
|
if (!function_exists('get_device_type')) {
|
|
function get_device_type(): array
|
|
{
|
|
// 获取HTTP请求头中的User-Agent字段
|
|
$userAgent = $_SERVER['HTTP_USER_AGENT'];
|
|
// 初始化设备信息数组
|
|
$deviceInfo = [
|
|
'isMobile' => false,
|
|
'isTablet' => false,
|
|
'deviceType' => 'Desktop',
|
|
'browser' => '',
|
|
'platform' => ''
|
|
];
|
|
|
|
// 检查是否为移动设备
|
|
if (preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $userAgent)) {
|
|
$deviceInfo['isMobile'] = true;
|
|
$deviceInfo['deviceType'] = 'Mobile';
|
|
}
|
|
|
|
// 检查是否为平板设备
|
|
if (preg_match('/tablet|ipad|playbook|silk/i', $userAgent)) {
|
|
$deviceInfo['isTablet'] = true;
|
|
$deviceInfo['deviceType'] = 'Tablet';
|
|
}
|
|
|
|
// 确定浏览器类型
|
|
if (strpos($userAgent, 'Firefox') !== false) {
|
|
$deviceInfo['browser'] = 'Mozilla Firefox';
|
|
} elseif (strpos($userAgent, 'Opera Mini') !== false || strpos($userAgent, 'Opera') !== false) {
|
|
$deviceInfo['browser'] = 'Opera';
|
|
} elseif (strpos($userAgent, 'Chrome') !== false) {
|
|
$deviceInfo['browser'] = 'Google Chrome';
|
|
} elseif (strpos($userAgent, 'Safari') !== false && strpos($userAgent, 'Version/') !== false) {
|
|
$deviceInfo['browser'] = 'Apple Safari';
|
|
} elseif (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident/7') !== false) {
|
|
$deviceInfo['browser'] = 'Internet Explorer';
|
|
}
|
|
|
|
// 确定操作系统平台
|
|
if (strpos($userAgent, 'Windows NT 10.0; Win64; x64') !== false && strpos($userAgent, 'WOW64') === false) {
|
|
$deviceInfo['platform'] = 'Windows 11';
|
|
} elseif (strpos($userAgent, 'Windows NT 10.0') !== false) {
|
|
$deviceInfo['platform'] = 'Windows 10';
|
|
} elseif (strpos($userAgent, 'Windows NT 6.3') !== false) {
|
|
$deviceInfo['platform'] = 'Windows 8.1';
|
|
} elseif (strpos($userAgent, 'Windows NT 6.2') !== false) {
|
|
$deviceInfo['platform'] = 'Windows 8';
|
|
} elseif (strpos($userAgent, 'Windows NT 6.1') !== false) {
|
|
$deviceInfo['platform'] = 'Windows 7';
|
|
} elseif (strpos($userAgent, 'Macintosh; Intel Mac OS X') !== false) {
|
|
$deviceInfo['platform'] = 'Mac OS X';
|
|
} elseif (strpos($userAgent, 'iPad') !== false) {
|
|
$deviceInfo['platform'] = 'iOS';
|
|
} elseif (strpos($userAgent, 'iPhone') !== false) {
|
|
$deviceInfo['platform'] = 'iOS';
|
|
} elseif (strpos($userAgent, 'Android') !== false) {
|
|
$deviceInfo['platform'] = 'Android';
|
|
} else {
|
|
$deviceInfo['platform'] = '未知';
|
|
}
|
|
|
|
return $deviceInfo;
|
|
}
|
|
} |