✏️ 正在编辑: Mailw.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/application/services/Mailw.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Zend_Http_Client as Http; class Service_Mailw { /** @var Service_Config */ private $configService; /** @var Service_Sincronizacao_Config_Cliente */ private $configCliente; /** @var int[] */ public const STATUS = [ 'unathorized' => 401 ]; /** @var int */ public const UMA_HORA = 3600; /** @var string */ public const ERRO = 'Ocorreu um erro durante a sincronização!'; public function __construct() { $this->configService = (service('config')->get())->mailw; $this->configCliente = service('sinc_cliente'); } /** * @param int|null $config * @return mixed * @throws Zend_Http_Client_Exception */ public function sincronizar(?int $config) { $configSincronizacao = new Model_UsuariosApi(); $dadosConfig = $configSincronizacao->exibir($config); if (empty($dadosConfig)) { throw new Core_Exception("Configurações não localizadas."); } $this->autenticarJWT(); $this->configCliente->setParameters($dadosConfig->toArray()); $http = $this->getHttpAddCliente(); foreach ($this->configCliente->toArray() as $key => $parameter) { $http->setParameterPost($key, $parameter); } return json_decode($http->request('POST')->getBody()); } /** * @return string */ public function getToken(): string { return (new Zend_Session_Namespace('mailw_connect'))->token; } private function autenticarJWT() { $session = new Zend_Session_Namespace('mailw_connect'); if ($session->token) { return; } $session->token = $this->getTokenRequest(); $session->setExpirationSeconds(self::UMA_HORA); } private function getTokenRequest() { $http = new Http($this->configService->host . "/auth"); $http->setParameterPost('username', $this->configService->usuario); $http->setParameterPost('password', $this->configService->senha); $result = json_decode( $http->request('POST')->getBody() ); return $result->token; } /** * @param string|null $token */ private function validarHttp($token): void { if (!($token)) { throw new DomainException(self::ERRO); } $this->configCliente->validarCliente(); } /** * @return Zend_Http_Client */ private function getHttpAddCliente(): Zend_Http_Client { $http = new Http($this->configService->host . "/clientes/novo"); $token = $this->getToken(); $this->validarHttp($token); $http->setParameterPost('token', $token); return $http; } }
💾 保存文件
← 返回文件管理器