storeManager ->getStore() ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA); } protected function isDirEmpty($dir) { if (!is_dir($dir)) { return false; // 或者抛出异常 } $files = scandir($dir); // 减去 . 和 .. 后,如果数量为0,则文件夹为空 return count($files) == 2; // 2 表示只有 . 和 .. } protected function execute(InputInterface $input, OutputInterface $output) { // $this->formRecordsNotification->execute(); // $output->writeln($this->directoryList->getPath('media')); // $content = "Hello world !"; // $ivStr128 = "1234567812345678"; // 16字节 // $AESSecretGCM256 = "IhHEhIvTS8zbVTY391GP8oHJ7RmSJ8pQ"; // 32字节 // $output->writeln(self::encryptGCMWithPhpseclib($content, $AESSecretGCM256, $ivStr128)); // $output->writeln($this->timezone->date()->format('Y-m-d H:i:s')); $this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); $product = $this->productRepository->get('MRDX20359', true); $existingEntries = $product->getMediaGalleryEntries(); if (!empty($existingEntries)) { $output->writeln(" 清理现有图片,共 " . count($existingEntries) . " 张"); // 清空媒体库条目 $product->setMediaGalleryEntries([]); // 清除图片角色 $product->setImage(null); $product->setSmallImage(null); $product->setThumbnail(null); $this->productRepository->save($product); // $output->writeln(" 现有图片清理完成"); } // $this->configWriter->save( // self::NO_PRICE_SKU_PATH, // '111111111111111111111', // ScopeConfigInterface::SCOPE_TYPE_DEFAULT, // 0 // ); // $this->cacheTypeList->cleanType('config'); // $this->importStock->execute(); return Command::SUCCESS; } public static function encryptGCMWithPhpseclib($content, $key, $iv) { $cipher = new AES('gcm'); $cipher->setPreferredEngine(SymmetricKey::ENGINE_OPENSSL_GCM); $cipher->setKey($key); $cipher->setNonce($iv); $cipher->setKeyLength(256); // 尝试设置256位标签 $cipherText = $cipher->encrypt($content); $tag = $cipher->getTag(); // 打包数据 $ivLength = pack('N', strlen($iv)); $byteBuffer = $ivLength . $iv . $cipherText . $tag; return base64_encode($byteBuffer); } }