Lumen使用加解密

1 . lumen禁用了生成APP_KEY的命令 php artisan key:generate

 2 . 解禁步骤 : 

        第一步 : 在 app/Console/Commands下创建文件 KeyGenerateCommand 并添加如下代码

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class KeyGenerateCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'key:generate';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Set the application key';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $key = $this->generateRandomKey();

        file_put_contents(base_path('.env'), preg_replace(
            '/^APP_KEY=[\w]*/m',
            'APP_KEY='.$key,
            file_get_contents(base_path('.env'))
        ));

        $this->info("Application key [$key] set successfully.");
    }

    /**
     * Generate a random key for the application.
     *
     * @return string
     */
    protected function generateRandomKey()
    {
        return Str::random(32);
    }

}

此处注意 str_random(32) 这函数不能用 

        第二步 : 在app/Console    Kernel.php 添加如下代码

/**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
     protected $commands = [
        //注入指令
        'App\Console\Commands\KeyGenerateCommand', 
    ];

        第三步 : 执行 php artisan key:generate

         至此 32位APP_KEY生成完毕 在 .env文件

        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值