123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- if (! function_exists('success')) {
- function success($data = [], $message = 'success', $code = 1)
- {
- return response()->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']);
- }
- }
|