douyi9597 2016-08-19 03:38
浏览 350

无法Crypt ::解密工匠命令Laravel / Lumen

I'm working on a project that need to store encrypted information, the store, update, show (used in the Controller) work fine when using use Illuminate\Support\Facades\Crypt;

But when i need to create a Command to run in schedule, in that Command i need to get the unencrypted code, but when i use it, it show

The MAC is invalid

Note: when i use use Crypt;, the code in the Controller work fine, but in the Command, it said

Class 'Crypt' not found

The code in Command (function topupSim() cause the error):

public function handle()
{
    Log::info("** TopUpForCriticalSimsCommand: started");

    $sims = Sim::getCriticalSims();
    foreach ($sims as $sim) {
        $telco_id = $sim->telco_id;

        //Find topup code with same telco
        $topup_code = TopupCode::getAvailableCode($telco_id);

        if ($topup_code) {
            /** @var TopupCode $topup_code */
            if (Engine::topupSim($sim, $topup_code)){
                Log::info("** TopUpForCriticalSimsCommand: topup success
                 for {$sim->phone_number} with code {$topup_code->getCensoredCode()}");
            }else{
                Log::info("** TopUpForCriticalSimsCommand: topup fail
                 for {$sim->phone_number} with code {$topup_code->getCensoredCode()}");
            }
        }
    }

    Log::info("** TopUpForCriticalSimsCommand: finished");
}

topupSim function, code that use Crypt:

public static function topupSim(Sim $sim, TopupCode $topupCode)
{
    $code = $topupCode->getCode();
    $serial = $topupCode->getSerial();

    //TODO: Do topup for sim
    if (false /*Success*/) {

        $topupCode->setUse();

        return true;
    }

    return false;
}

2 function getCode(), getSerial() are using Crypt, these 2 functions are in the Model

public function getCode()
{
    $code = Crypt::decrypt($this->getAttribute('code'));
    return $code;
}

public function getSerial()
{
    $serial = Crypt::decrypt($this->getAttribute('serial'));
    return $serial;
}

Log file:

[2016-08-19 02:58:57] lumen.INFO: ** TopUpForCriticalSimsCommand: started  
[2016-08-19 03:01:02] lumen.ERROR: exception 'Illuminate\Contracts\Encryption\DecryptException' with message 'The MAC is invalid.' in D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\encryption\BaseEncrypter.php:48
Stack trace:
#0 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\encryption\Encrypter.php(96): Illuminate\Encryption\BaseEncrypter->getJsonPayload('eyJpdiI6InBFT2d...')
#1 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\support\Facades\Facade.php(218): Illuminate\Encryption\Encrypter->decrypt('eyJpdiI6InBFT2d...')
#2 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\app\Models\TopupCode.php(114): Illuminate\Support\Facades\Facade::__callStatic('decrypt', Array)
#3 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\app\Models\TopupCode.php(114): Illuminate\Support\Facades\Crypt::decrypt('eyJpdiI6InBFT2d...')
#4 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\app\Engine.php(721): Ved\SmsGateway\Models\TopupCode->getCode()
#5 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\app\Console\Commands\TopUpForCriticalSimsCommand.php(57): Ved\SmsGateway\Engine::topupSim(Object(Ved\SmsGateway\Models\Sim), Object(Ved\SmsGateway\Models\TopupCode))
#6 [internal function]: Ved\SmsGateway\Console\Commands\TopUpForCriticalSimsCommand->handle()
#7 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\container\Container.php(507): call_user_func_array(Array, Array)
#8 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\console\Command.php(169): Illuminate\Container\Container->call(Array)
#9 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\symfony\console\Command\Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\illuminate\console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\symfony\console\Application.php(791): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\symfony\console\Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Ved\SmsGateway\Console\Commands\TopUpForCriticalSimsCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\symfony\console\Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\vendor\laravel\lumen-framework\src\Console\Kernel.php(69): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 D:\working-tools\xampp\htdocs\VedSmsGateway\source\sms_gateway\artisan(35): Laravel\Lumen\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 {main}  

i tried:

composer dump-autoload
composer clear-cache

but no success

Anyone know, please help, thanks in advance

  • 写回答

1条回答 默认 最新

  • dongshenling6585 2016-08-19 04:47
    关注

    OK, so my project consist 2 smaller projects linked together (admin site and api/backend)

    The problem was the key in config/app.php in the api/backend side is different from the admin site. I've changed APP_KEY in .env, now everything is working fine!

    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入