feat: admin login

This commit is contained in:
2024-10-27 00:34:45 +08:00
parent 3a39ff3790
commit d76e37a81d
18 changed files with 698 additions and 3 deletions

60
app/Extend/SystemUtil.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
namespace App\Extend;
use Hyperf\Context\Context;
use Psr\Http\Message\ServerRequestInterface;
use function Hyperf\Support\env;
class SystemUtil
{
/**
* prod 1=生产环境 0=开发环境
* @return bool
*/
static function checkProEnv()
{
return Env('APP_ENV') == 'prod';
}
/**
* 获取客户端 ip
* @return mixed|string
*/
static function getClientIp()
{
$request = Context::get(ServerRequestInterface::class);
$ip_addr = $request->getHeaderLine('x-forwarded-for');
if (self::verifyIp($ip_addr)) {
return $ip_addr;
}
$ip_addr = $request->getHeaderLine('remote-host');
if (self::verifyIp($ip_addr)) {
return $ip_addr;
}
$ip_addr = $request->getHeaderLine('x-real-ip');
if (self::verifyIp($ip_addr)) {
return $ip_addr;
}
$ip_addr = $request->getServerParams()['remote_addr'] ?? '0.0.0.0';
if (self::verifyIp($ip_addr)) {
return $ip_addr;
}
return '0.0.0.0';
}
/**
* 验证ip
* @param $realIp
* @return mixed
*/
static function verifyIp($realIp): mixed
{
return filter_var($realIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
}