文件
yjyf/server/addons/epay/library/hyperf/utils/src/Network.php
YuanWen 78d45eea74 chore: 新增epay和cos插件相关类库及配置文件
- 新增epay v2、v3、v3new版本的支付类库及证书文件
- 新增cos云存储类库文件
- 调整文件上传保存格式为按分类存储
- 修复会员、规则、类目等语言翻译键名
- 新增小程序图标等静态资源文件
2026-11-04 09:33:57 +08:00

47 行
1.3 KiB
PHP

<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Utils;
use RuntimeException;
class Network
{
public static function ip(): string
{
$ips = [];
if (function_exists('swoole_get_local_ip')) {
$ips = swoole_get_local_ip();
}
if (empty($ips) && function_exists('net_get_interfaces')) {
foreach (net_get_interfaces() ?: [] as $name => $value) {
foreach ($value['unicast'] as $item) {
if (! isset($item['address'])) {
continue;
}
if (! Str::contains($item['address'], '::') && $item['address'] !== '127.0.0.1') {
$ips[$name] = $item['address'];
}
}
}
}
if (is_array($ips) && ! empty($ips)) {
return current($ips);
}
/** @var mixed|string $ip */
$ip = gethostbyname(gethostname());
if (is_string($ip)) {
return $ip;
}
throw new RuntimeException('Can not get the internal IP.');
}
}