我正在研究一个需要存储加密信息的项目,使用use IlluminateSupportFacadesCrypt;
时,存储,更新,显示(在控制器中使用)工作良好
但是当我需要创建一个命令来运行时,在该命令中我需要获得未加密的代码,但是当我使用它时,它显示
MAC无效
注意:当我使用use Crypt;
时,控制器中的代码工作正常,但在命令中,它说
没有找到"Crypt"类
命令(函数topupSim()
导致错误)中的代码:
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
函数,使用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函数getCode()
, getSerial()
使用Crypt,这2函数在模型
public function getCode()
{
$code = Crypt::decrypt($this->getAttribute('code'));
return $code;
}
public function getSerial()
{
$serial = Crypt::decrypt($this->getAttribute('serial'));
return $serial;
}
日志文件:[2016-08-19 02:58:57] lumen.INFO: ** TopUpForCriticalSimsCommand: started
[2016-08-19 03:01:02] lumen.ERROR: exception 'IlluminateContractsEncryptionDecryptException' with message 'The MAC is invalid.' in D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminateencryptionBaseEncrypter.php:48
Stack trace:
#0 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminateencryptionEncrypter.php(96): IlluminateEncryptionBaseEncrypter->getJsonPayload('eyJpdiI6InBFT2d...')
#1 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminatesupportFacadesFacade.php(218): IlluminateEncryptionEncrypter->decrypt('eyJpdiI6InBFT2d...')
#2 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayappModelsTopupCode.php(114): IlluminateSupportFacadesFacade::__callStatic('decrypt', Array)
#3 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayappModelsTopupCode.php(114): IlluminateSupportFacadesCrypt::decrypt('eyJpdiI6InBFT2d...')
#4 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayappEngine.php(721): VedSmsGatewayModelsTopupCode->getCode()
#5 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayappConsoleCommandsTopUpForCriticalSimsCommand.php(57): VedSmsGatewayEngine::topupSim(Object(VedSmsGatewayModelsSim), Object(VedSmsGatewayModelsTopupCode))
#6 [internal function]: VedSmsGatewayConsoleCommandsTopUpForCriticalSimsCommand->handle()
#7 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminatecontainerContainer.php(507): call_user_func_array(Array, Array)
#8 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminateconsoleCommand.php(169): IlluminateContainerContainer->call(Array)
#9 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorsymfonyconsoleCommandCommand.php(256): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#10 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorilluminateconsoleCommand.php(155): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#11 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorsymfonyconsoleApplication.php(791): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#12 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorsymfonyconsoleApplication.php(186): SymfonyComponentConsoleApplication->doRunCommand(Object(VedSmsGatewayConsoleCommandsTopUpForCriticalSimsCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#13 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorsymfonyconsoleApplication.php(117): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#14 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayvendorlaravellumen-frameworksrcConsoleKernel.php(69): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#15 D:working-toolsxampphtdocsVedSmsGatewaysourcesms_gatewayartisan(35): LaravelLumenConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#16 {main}
我试着:
composer dump-autoload
composer clear-cache
但没有成功
谁知道,请帮助,提前感谢
OK,所以我的项目包括2个较小的项目链接在一起(管理网站和api/后端)
问题是在api/后端配置/app.php中的key
与管理站点不同。我已经改变了APP_KEY
.env,现在一切都很好!