diff --git a/composer.json b/composer.json index a6a4d47..71cd3d4 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "nfephp-org/sped-nfse-ginfes", + "name": "jvkrypton/sped-nfse-ginfes", "type": "library", "description": "API para geração e comunicação de RPS e NFSe no padão Ginfes.", "keywords": ["nfe","nfse","sped","nfephp"], - "homepage": "https://github.com/nfephp-org/sped-nfse-ginfes", + "homepage": "https://github.com/jvkrypton/sped-nfse-ginfes", "license": ["LGPL-3.0-or-later", "GPL-3.0-or-later", "MIT"], "authors": [ { @@ -14,13 +14,13 @@ }, { "name": "Comunidade NFePHP", - "homepage": "https://github.com/nfephp-org/sped-nfe/graphs/contributors" + "homepage": "https://github.com/jvkrypton/sped-nfe/graphs/contributors" } ], "require": { "php" : ">= 7.1", - "nfephp-org/sped-common" : "^5.0", "justinrainbow/json-schema": "^5.2", + "league/flysystem": "^3.23", "ext-zlib": "*", "ext-dom": "*", "ext-openssl": "*", diff --git a/src/Common/Soap/SoapBase.php b/src/Common/Soap/SoapBase.php index 4ee4857..ecab62c 100755 --- a/src/Common/Soap/SoapBase.php +++ b/src/Common/Soap/SoapBase.php @@ -21,8 +21,9 @@ use NFePHP\Common\Exception\RuntimeException; use NFePHP\Common\Strings; use League\Flysystem\Filesystem; -use League\Flysystem\Adapter\Local; +use League\Flysystem\Local\LocalFilesystemAdapter; use Psr\Log\LoggerInterface; +use Illuminate\Support\Facades\File; abstract class SoapBase implements SoapInterface { @@ -99,7 +100,7 @@ abstract class SoapBase implements SoapInterface */ protected $disableCertValidation = false; /** - * @var \League\Flysystem\Adapter\Local + * @var \League\Flysystem\Local\LocalFilesystemAdapter; */ protected $adapter; /** @@ -158,9 +159,9 @@ public function __construct( ) { $this->logger = $logger; $this->certificate = $this->checkCertValidity($certificate); - $this->setTemporaryFolder(sys_get_temp_dir() . '/sped/'); + $this->setTemporaryFolder(storage_path('nfe') . '/'); } - + /** * Check if certificate is valid * @param Certificate $certificate @@ -181,7 +182,7 @@ private function checkCertValidity(Certificate $certificate = null) } return $certificate; } - + /** * Destructor * Clean temporary files @@ -190,7 +191,7 @@ public function __destruct() { $this->removeTemporarilyFiles(); } - + /** * Disables the security checking of host and peer certificates * @param bool $flag @@ -200,7 +201,7 @@ public function disableSecurity($flag = false) $this->disablesec = $flag; return $this->disablesec; } - + /** * ONlY for tests * @param bool $flag @@ -222,7 +223,7 @@ public function loadCA($capath) $this->casefaz = $capath; } } - + /** * Set option to encript private key before save in filesystem * for an additional layer of protection @@ -233,7 +234,7 @@ public function setEncriptPrivateKey($encript = true) { return $this->encriptPrivateKey = $encript; } - + /** * Set another temporayfolder for saving certificates for SOAP utilization * @param string $folderRealPath @@ -243,15 +244,15 @@ public function setTemporaryFolder($folderRealPath) $this->tempdir = $folderRealPath; $this->setLocalFolder($folderRealPath); } - + /** * Set Local folder for flysystem * @param string $folder */ protected function setLocalFolder($folder = '') { - $this->adapter = new Local($folder); - $this->filesystem = new Filesystem($this->adapter); + //$this->adapter = new LocalFilesystemAdapter($folder); + $this->filesystem = new \NFePHP\Common\Files($folder); } /** @@ -263,7 +264,7 @@ public function setDebugMode($value = false) { return $this->debugmode = $value; } - + /** * Set certificate class for SSL comunications * @param Certificate $certificate @@ -272,7 +273,7 @@ public function loadCertificate(Certificate $certificate) { $this->certificate = $this->checkCertValidity($certificate); } - + /** * Set logger class * @param LoggerInterface $logger @@ -281,7 +282,7 @@ public function loadLogger(LoggerInterface $logger) { return $this->logger = $logger; } - + /** * Set timeout for communication * @param int $timesecs @@ -290,7 +291,7 @@ public function timeout($timesecs) { return $this->soaptimeout = $timesecs; } - + /** * Set security protocol * @param int $protocol @@ -300,7 +301,7 @@ public function protocol($protocol = self::SSL_DEFAULT) { return $this->soapprotocol = $protocol; } - + /** * Set prefixes * @param array $prefixes @@ -310,7 +311,7 @@ public function setSoapPrefix($prefixes) { return $this->prefixes = $prefixes; } - + /** * Set proxy parameters * @param string $ip @@ -325,7 +326,7 @@ public function proxy($ip, $port, $user, $password) $this->proxyUser = $user; $this->proxyPass = $password; } - + /** * Send message to webservice */ @@ -336,7 +337,7 @@ abstract public function send( $envelope, $parameters ); - + /** * Mount soap envelope * @param string $request @@ -372,7 +373,7 @@ protected function makeEnvelopeSoap( . ""; return $envelope; } - + /** * Temporarily saves the certificate keys for use cURL or SoapClient */ @@ -383,10 +384,12 @@ public function saveTemporarilyKeyFiles() 'Certificate not found.' ); } + $this->certsdir = $this->certificate->getCnpj() . '/certs/'; $this->prifile = $this->certsdir. Strings::randomString(10).'.pem'; $this->pubfile = $this->certsdir . Strings::randomString(10).'.pem'; $this->certfile = $this->certsdir . Strings::randomString(10).'.pem'; + $ret = true; $private = $this->certificate->privateKey; if ($this->encriptPrivateKey) { @@ -401,10 +404,12 @@ public function saveTemporarilyKeyFiles() $this->temppass ); } + $ret &= $this->filesystem->put( $this->prifile, $private ); + $ret &= $this->filesystem->put( $this->pubfile, $this->certificate->publicKey @@ -418,8 +423,10 @@ public function saveTemporarilyKeyFiles() 'Unable to save temporary key files in folder.' ); } + + $this->removeTemporarilyFiles(); } - + /** * Delete all files in folder */ @@ -457,7 +464,7 @@ public function removeTemporarilyFiles() } } } - + /** * Save request envelope and response for debug reasons * @param string $operation