json([ 'code' => $code, 'msg' => $message, 'data' => $data, ],200); } } if (! function_exists('error')) { function error($message = 'error', $code = 0) { return response()->json([ 'code' => $code, 'msg' => $message, ],400); } } if (!function_exists('_microtime')) { function _microtime($length = 13) { $val = pow(10, $length - 10); list($t1, $t2) = explode(' ', microtime()); return (int)sprintf('%.0f', (floatval($t1) + floatval($t2)) * $val); } } if (!function_exists('params')) { function params(): array { return request()->all(); } } if (!function_exists('_header')) { function _header($key) { return request()->header($key); } } if (!function_exists('ip')) { function ip() { if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); foreach ($arr as $ip) { $ip = trim($ip); if ($ip != 'unknown') { $realip = $ip; break; } } } else if (isset($_SERVER['HTTP_CLIENT_IP'])) { $realip = $_SERVER['HTTP_CLIENT_IP']; } else if (isset($_SERVER['REMOTE_ADDR'])) { $realip = $_SERVER['REMOTE_ADDR']; } else { $realip = '0.0.0.0'; } } 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'); } preg_match('/[\\d\\.]{7,15}/', $realip, $onlineip); return (!empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0'); } } if (!function_exists('ua')) { function ua(): string { return strtolower($_SERVER['HTTP_USER_AGENT']); } }