19980617, 'msg' => '测试返回', 'data' => $data ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT )); } } if (!function_exists('is_encrypted')) { function is_encrypted($data): bool { if (!is_string($data)) { return false; } // 这里应该有逻辑来判断$data是否已经被加密。未加密是true return strpos($data, 'xk_ase_256_') === 0; } } 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', ]; // 检查是否为移动设备 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'; } // 确定浏览器类型 $br = $_SERVER['HTTP_USER_AGENT']; switch ($br) { case strpos($br, 'MSIE') !== false: $deviceInfo['browser'] = 'MSIE'; break; case strpos($br, 'Edg') !== false: $deviceInfo['browser'] = 'Microsoft Edge'; break; case strpos($br, 'Firefox') !== false: $deviceInfo['browser'] = 'Firefox'; break; case strpos($br, 'Chrome') !== false: $deviceInfo['browser'] = 'Chrome'; break; case strpos($br, 'Safari') !== false: $deviceInfo['browser'] = 'Safari'; break; case strpos($br, 'Opera' ): $deviceInfo['browser'] = 'Opera'; break; case strpos($br, 'Api' ): $deviceInfo['browser'] = 'Api Post'; break; default: $deviceInfo['browser'] = 'Other'; } // 确定操作系统平台 $os = $_SERVER['HTTP_USER_AGENT']; switch(true) { case strpos($os, 'Windows') !== false: $deviceInfo['platform'] = 'Windows'; break; case strpos($os, 'Macintosh') !== false: $deviceInfo['platform'] = 'Mac'; break; case strpos($os, 'Linux') !== false: $deviceInfo['platform'] = 'Linux'; break; case strpos($os, 'Android') !== false: $deviceInfo['platform'] = 'Android'; break; case strpos($os, 'iOS') !== false: $deviceInfo['platform'] = 'iOS'; break; case strpos($os, 'Api') !== false: $deviceInfo['platform'] = 'Api Post'; break; default: $deviceInfo['platform'] = 'Unknown'; } // $deviceInfo['ip'] = get_client_ip(); $deviceInfo['ip'] = $_SERVER['HTTP_X_FORWARDED_FOR']?? '127.0.0.1'; // $deviceInfo['ip_address'] = cc_get_ip_lookup(); return $deviceInfo; } } /** * 获取ip所属地 * * @return true */ if ( !function_exists('cc_get_ip_lookup') ) { function cc_get_ip_lookup($ip = ''): array { if ( empty($ip) ) { $ip = get_client_ip(); } $result = (new GuzzleHttp\Client())->get('https://api.vore.top/api/Weather?ip='. $ip); $weather = json_decode($result->getBody()->getContents(), true); if ( empty($weather) ) { $data = [ 'weather' => '未知', 'temperature' => '未知', 'winddirection' => '未知', 'reporttime' => '未知', 'area' => '未知', 'info' => '未知', ]; } else { $data = [ 'area' => $weather['data']['ipdata']['area'], 'info' => $weather['data']['ipdata']['info'], ]; } return $data; } }