app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build(); } else { $location = $this->app->route->buildUrl($url, [])->suffix($suffix)->domain($domain)->build(); } if (empty($vars)) { $location = substr($location . ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr), 0, -1) . ".{$url_html_suffix}"; } else { $location .= ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr) . ".{$url_html_suffix}"; } } else { $location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build(); } return $location; } /** * 二维数组转化为字符串,中间用,隔开 * @param $arr * @param string $glue * @return false|string */ private function arr_to_str($arr, $glue = "/") { $t = ''; foreach ($arr as $k => $v) { $t .= $k . $glue . $v . $glue; } // 利用字符串截取函数消除最后一个 return substr($t, 0, -1); } /** * @var array */ private $result = []; /** * 第一个mac地址 * @var */ private $macAddr; /** * 获取电脑MAC地址 * @return mixed */ public function mac() { switch (strtolower(PHP_OS)) { case "solaris": case "aix": case 'unix': break; case "linux": $this->getLinux(); break; default: $this->getWindows(); break; } $tem = array(); foreach ($this->result as $val) { if (preg_match("/[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f]/i", $val, $tem)) { $this->macAddr = $tem[0];//多个网卡时,会返回第一个网卡的mac地址,一般够用。 break; //$this->macAddrs[] = $temp_array[0];//返回所有的mac地址 } } unset($temp_array); return $this->macAddr; } /** * Linux系统 * @return array */ private function getLinux(): array { @exec("ifconfig -a", $this->result); return $this->result; } /** * Windows系统 */ private function getWindows(): void { @exec("ipconfig /all", $this->result); if ($this->result) { return; } $ipconfig = $_SERVER["WINDIR"] . "\system32\ipconfig.exe"; if (is_file($ipconfig)) { @exec($ipconfig . " /all", $this->result); return; } @exec($_SERVER["WINDIR"] . "\system\ipconfig.exe /all", $this->result); } /** * 获取Linux服务器IP * @return string */ public function linuxIp() { try { $ip_cmd = "ifconfig eth0 | sed -n '/inet addr/p' | awk '{print $2}' | awk -F ':' '{print $2}'"; return trim(exec($ip_cmd)); } catch (Exception $e) { return "0.0.0.0"; } } }