zoukankan      html  css  js  c++  java
  • laravel路由导出和参数加密

    路由导出

    代码位置:vendorlaravelframeworksrcIlluminateFoundationConsoleRouteListCommand.php

    protected function getRouteInformation(Route $route) {
    	$data       = $this->filterRoute([
    		'host'       => $route->domain(),
    		'method'     => implode('|', $route->methods()),
    		'uri'        => $route->uri(),
    		'name'       => $route->getName(),
    		'action'     => $route->getActionName(),
    		'middleware' => $this->getMiddleware($route),
    	]);
    	$path       = "./routeRewrite.log";
    	$fp         = fopen($path, "a+");
    	$before     = $route->uri();  //加密前
    	$after      = encrypt_aes($before, AES_KEY); //加密后
    	$middleware = $this->getMiddleware($route);
    	$array      = explode(",", $middleware);
    	$str        = "";
    	foreach ($array as $v) {
    		$str = $str . "'{$v}',";
    	}
    	$str   = substr($str, 0, strlen($str) - 1);
    	$route = "Route::post('{$after}', '\{$route->getActionName()}')->middleware({$str});";
    	fwrite($fp, $route . "
    ");
    	fclose($fp);
    	return $data;
    }
    

    中间件

    class AfterMiddleware {
        public function handle($request, Closure $next) {
            if ( $request->isMethod('post') ) {
                $str = file_get_contents("php://input");
                $key = AES_KEY;
                $data = decrypt_aes($str, $key);
                $body = json_decode($data, true);
                $request->merge($body);
                $response = $next($request);
                if ($response->status() == 200) {
                    $data = encrypt_aes($response->content(), $key);
                    $response->setContent($data);
                }
                return $response;
            }
            return $next($request);
    
        }
    }
    

    加密解密

    if (!function_exists('encrypt_aes')) {
        function encrypt_aes($data, $key) {
            $data = openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
            return base64_encode($data);
        }
    }
    if (!function_exists('decrypt_aes')) {
        function decrypt_aes($data, $key) {
            $encrypted = base64_decode($data);
            return openssl_decrypt($encrypted, 'aes-128-ecb', $key, OPENSSL_RAW_DATA);
        }
    }
    
  • 相关阅读:
    python不同包之间调用时提示文件模块不存在的问题
    adb shell 查看内存信息
    adb shell top 使用
    Android读取logcat信息
    父类的引用对象指向子类的对象
    我的阿里梦——淘宝前端必备技能
    我也做了一个1/4圆形菜单
    可编辑tab选项卡
    canvas 之
    canvas之----浮动小球
  • 原文地址:https://www.cnblogs.com/HappyTeemo/p/15476013.html
Copyright © 2011-2022 走看看