<?php
namespace app\common\middleware;

use Exception;
use app\admin\model\IpConfig;

//验证Ip
class CheckIp
{
    public function handle($request, \Closure $next)
    {
        try {
            $ip = $request->ip();
            $whitelist = IpConfig::getWhitelist();
            if(!in_array($ip, $whitelist)){
                $blacklist = IpConfig::getBlacklist();
                if(in_array($ip, $blacklist)){
                    return shutdown(lang('system.ipError'), 10002);
                }
            }
        } catch (Exception $exception) {
            return shutdown($errorMsgArr[$exception->getMessage()] ?? $exception->getMessage(), 10002);
        }
      
        return $next($request);
    }
}