/** * Finally returns a SoapClient instance. * * @return \BeSimple\SoapServer\SoapServer */ public function build() { $this->validateOptions(); use_soap_error_handler($this->errorReporting); $server = new SoapServer($this->wsdl, $this->getSoapOptions()); if (null !== $this->persistence) { $server->setPersistence($this->persistence); } if (null !== $this->handlerClass) { $server->setClass($this->handlerClass); } elseif (null !== $this->handlerObject) { $server->setObject($this->handlerObject); } return $server; }
/** * Run webservice * * @param Mage_Api_Controller_Action $controller * @return Mage_Api_Model_Server_Adapter_Soap */ public function run() { $urlModel = Mage::getModel('core/url')->setUseSession(false); if ($this->getController()->getRequest()->getParam('wsdl')) { $wsdlConfig = Mage::getModel('api/wsdl_config'); $wsdlConfig->setHandler($this->getHandler())->init(); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($wsdlConfig->getWsdlContent()); } elseif ($this->_extensionLoaded()) { $this->_soap = new SoapServer($urlModel->getUrl('*/*/*', array('wsdl' => 1))); use_soap_error_handler(false); $this->_soap->setClass($this->getHandler()); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($this->_soap->handle()); } else { $this->fault('0', 'Unable to load Soap extension on the server'); } return $this; }
/** * Try to instantiate Zend_Soap_Server * If schema import error is caught, it will retry in 1 second. * * @throws Zend_Soap_Server_Exception */ protected function _instantiateServer() { $apiConfigCharset = Mage::getStoreConfig('api/config/charset'); ini_set('soap.wsdl_cache_enabled', '0'); $tries = 0; do { $retry = false; try { $this->_soap = new Zend_Soap_Server($this->getWsdlUrl(array("wsdl" => 1)), array('encoding' => $apiConfigCharset)); } catch (SoapFault $e) { if (false !== strpos($e->getMessage(), "can't import schema from 'http://schemas.xmlsoap.org/soap/encoding/'")) { $retry = true; sleep(1); } else { throw $e; } $tries++; } } while ($retry && $tries < 5); use_soap_error_handler(false); $this->_soap->setReturnResponse(true)->setClass($this->getHandler()); }
/** * Estabelece comunicaçao com servidor SOAP 1.1 ou 1.2 da SEFAZ, * usando as chaves publica e privada parametrizadas na contrução da classe. * Conforme Manual de Integração Versão 4.0.1 * * @param string $urlsefaz * @param string $namespace * @param string $cabecalho * @param string $dados * @param string $metodo * @param integer $ambiente tipo de ambiente 1 - produção e 2 - homologação * @param string $UF unidade da federação, necessário para diferenciar AM, MT e PR * @return mixed false se houve falha ou o retorno em xml do SEFAZ */ public function send($siglaUF = '', $namespace = '', $cabecalho = '', $dados = '', $metodo = '', $tpAmb = '2') { try { if (!class_exists("SoapClient")) { $msg = "A classe SOAP não está disponível no PHP, veja a configuração."; throw new Exception\RuntimeException($msg); } $soapFault = ''; //ativa retorno de erros soap use_soap_error_handler(true); //versão do SOAP $soapver = SOAP_1_2; if ($tpAmb == 1) { $ambiente = 'producao'; } else { $ambiente = 'homologacao'; } $usef = "_{$metodo}.asmx"; $urlsefaz = "{$this->pathWsdl}/{$ambiente}/{$siglaUF}{$usef}"; if ($this->enableSVAN) { //se for SVAN montar o URL baseado no metodo e ambiente $urlsefaz = "{$this->pathWsdl}/{$ambiente}/SVAN{$usef}"; } if ($this->enableSCAN) { //se for SCAN montar o URL baseado no metodo e ambiente $urlsefaz = "{$this->pathWsdl}/{$ambiente}/SCAN{$usef}"; } if ($this->enableSVRS) { //se for SVRS montar o URL baseado no metodo e ambiente $urlsefaz = "{$this->pathWsdl}/{$ambiente}/SVRS{$usef}"; } if ($this->enableSVCAN) { //se for SVCAN montar o URL baseado no metodo e ambiente $urlsefaz = "{$this->pathWsdl}/{$ambiente}/SVCAN{$usef}"; } if ($this->enableSVCRS) { //se for SVCRS montar o URL baseado no metodo e ambiente $urlsefaz = "{$this->pathWsdl}/{$ambiente}/SVCRS{$usef}"; } if ($this->soapTimeout == 0) { $tout = 999999; } else { $tout = $this->soapTimeout; } //completa a url do serviço para baixar o arquivo WSDL $sefazURL = $urlsefaz . '?WSDL'; $this->soapDebug = $urlsefaz; $options = array('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => true, 'soap_version' => $soapver, 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL, 'local_cert' => $this->certKEY, 'trace' => true, 'compression' => 0, 'exceptions' => true, 'connection_timeout' => $tout, 'cache_wsdl' => WSDL_CACHE_NONE); //instancia a classe soap $oSoapClient = new CorrectedSoapClient($sefazURL, $options); //monta o cabeçalho da mensagem $varCabec = new SoapVar($cabecalho, XSD_ANYXML); $header = new SoapHeader($namespace, 'nfeCabecMsg', $varCabec); //instancia o cabeçalho $oSoapClient->__setSoapHeaders($header); //monta o corpo da mensagem soap $varBody = new SoapVar($dados, XSD_ANYXML); //faz a chamada ao metodo do webservices $resp = $oSoapClient->__soapCall($metodo, array($varBody)); if (is_soap_fault($resp)) { $soapFault = "SOAP Fault: (faultcode: {$resp->faultcode}, faultstring: {$resp->faultstring})"; } $resposta = $oSoapClient->__getLastResponse(); $this->soapDebug .= "\n" . $soapFault; $this->soapDebug .= "\n" . $oSoapClient->__getLastRequestHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastRequest(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponseHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponse(); } catch (Exception\RuntimeException $e) { $this->aError[] = $e->getMessage(); return false; } return $resposta; }
/** * Enables SOAP Error handling, if sf_debug is true, disables it otherwise. */ protected function initializeErrorHandling() { use_soap_error_handler(sfConfig::get('sf_debug')); }
/** * __sendSOAP * Estabelece comunicaçao com servidor SOAP 1.1 ou 1.2 da SEFAZ, * usando as chaves publica e privada parametrizadas na contrução da classe. * Conforme Manual de Integração Versão 4.0.1 * * @name __sendSOAP * @param string $urlsefaz * @param string $namespace * @param string $cabecalho * @param string $dados * @param string $metodo * @param numeric $ambiente tipo de ambiente 1 - produção e 2 - homologação * @param string $UF unidade da federação, necessário para diferenciar AM, MT e PR * @return mixed false se houve falha ou o retorno em xml do SEFAZ */ protected function __sendSOAP($urlsefaz, $namespace, $cabecalho, $dados, $metodo, $ambiente, $UF = '') { //ativa retorno de erros soap use_soap_error_handler(true); //versão do SOAP $soapver = SOAP_1_2; if ($ambiente == 1) { $ambiente = 'producao'; } else { $ambiente = 'homologacao'; } //monta a terminação do URL switch ($metodo) { case 'mdfeRecepcaoLote': $usef = "MDFeRecepcao"; break; case 'mdfeRetRecepcao': $usef = "MDFeRetRecepcao"; break; /*case 'MDFeCancelamento': $usef = "CteCancelamento"; break; case 'MDFeInutilizacao': $usef = "CteInutilizacao"; break;*/ /*case 'MDFeCancelamento': $usef = "CteCancelamento"; break; case 'MDFeInutilizacao': $usef = "CteInutilizacao"; break;*/ case 'mdfeRecepcaoEvento': $usef = "MDFeRecepcaoEvento"; break; case 'mdfeConsultaMDF': $usef = "MDFeConsulta"; break; case 'mdfeStatusServicoMDF': $usef = "MDFeStatusServico"; break; } /*//para os estados de AM, MT e PR é necessário usar wsdl baixado para acesso ao webservice if ($UF=='AM' || $UF=='MT' || $UF=='PR'){ $urlsefaz = "$this->URLbase/wsdl/2.00/$ambiente/$UF$usef"; } if ($this->enableSVAN){ //se for SVAN montar o URL baseado no metodo e ambiente $urlsefaz = "$this->URLbase/wsdl/2.00/$ambiente/SVAN$usef"; } //verificar se SCAN ou SVAN if ($this->enableSCAN){ //se for SCAN montar o URL baseado no metodo e ambiente $urlsefaz = "$this->URLbase/wsdl/2.00/$ambiente/SCAN$usef"; }*/ //completa a url do serviço para baixar o arquivo WSDL $URL = $urlsefaz . '?WSDL'; $this->soapDebug = $urlsefaz; $options = array('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => $soapver, 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL, 'local_cert' => $this->certKEY, 'trace' => true, 'compression' => 0, 'exceptions' => false, 'cache_wsdl' => WSDL_CACHE_NONE); //instancia a classe soap $oSoapClient = new NFeSOAP2Client($URL, $options); //monta o cabeçalho da mensagem $varCabec = new SoapVar($cabecalho, XSD_ANYXML); $header = new SoapHeader($namespace, 'mdfeCabecMsg', $varCabec); //instancia o cabeçalho $oSoapClient->__setSoapHeaders($header); //monta o corpo da mensagem soap $varBody = new SoapVar($dados, XSD_ANYXML); $resp = $oSoapClient->__soapCall($metodo, array($varBody)); if (is_soap_fault($resp)) { $soapFault = "SOAP Fault: (faultcode: {$resp->faultcode}, faultstring: {$resp->faultstring})"; } $resposta = $oSoapClient->__getLastResponse(); $this->soapDebug .= "\n" . $soapFault; $this->soapDebug .= "\n" . $oSoapClient->__getLastRequestHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastRequest(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponseHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponse(); return $resposta; }
<?php /** * Servidor SOAP del Colegio Oficial . * * @author Mario Contreras García * @author Guillermo Gallego Gallego * @copyright Veridata s.l. 2015 */ use_soap_error_handler(true); // Definimos constantes de depuración define("DEBUG_LOG", 1); define("DEBUG_ERROR_SQL", 2); define("DEBUG_QUERY", 4); define("DEBUG_TIEMPO", 8); require_once "include/funciones.php"; $respError = new respuestaError(); $entorno = "test"; if (stripos($_SERVER["SCRIPT_FILENAME"], "pro")) { $entorno = "pro"; } define("ENTORNO", $entorno); define("NOMBRE_WEB_SERVICE", basename(__FILE__, ".php")); define("WSDL", NOMBRE_WEB_SERVICE . ".wsdl"); $fcheroINI = NOMBRE_WEB_SERVICE . ".ini"; if (file_exists($fcheroINI) && is_readable($fcheroINI)) { $settings = parse_ini_file($fcheroINI, true); } else { throw new SoapFault("Server.0", "Error, el fichero {$fcheroINI} no existe o no se puede abrir para lectura."); /*$soapResponse = $respError->SOAPFault("Server.0", "Error, el fichero $fcheroINI no existe o no se puede abrir para lectura."); print $soapResponse;
/** * Initialize SOAP Server. * * @return Mage_Webapi_Model_Soap_Server */ protected function _initSoapServer() { $this->_soapServer->initWsdlCache(); $this->_soapServer->setWSDL($this->_soapServer->generateUri(true))->setEncoding($this->_soapServer->getApiCharset())->setSoapVersion(SOAP_1_2)->setClassmap($this->_apiConfig->getTypeToClassMap()); use_soap_error_handler(false); // TODO: Headers are not available at this point. // $this->_soapHandler->setRequestHeaders($this->_getRequestHeaders()); $this->_soapServer->setReturnResponse(true)->setObject($this->_soapHandler); return $this->_soapServer; }
/** * Run webservice * * @param Mage_Api_Controller_Action $controller * @return Mage_Api_Model_Server_Adapter_Soap */ public function run() { if ($this->getController()->getRequest()->getParam('wsdl')) { // Generating wsdl content from template $io = new Varien_Io_File(); $io->open(array('path' => Mage::getModuleDir('etc', 'Mage_Api'))); $wsdlContent = $io->read('wsdl.xml'); $template = Mage::getModel('core/email_template_filter'); $wsdlConfig = new Varien_Object(); $wsdlConfig->setUrl(Mage::getUrl('*/*/*')); $wsdlConfig->setName('Magento'); $wsdlConfig->setHandler($this->getHandler()); $template->setVariables(array('wsdl' => $wsdlConfig)); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($template->filter($wsdlContent)); } elseif ($this->_extensionLoaded()) { $this->_soap = new SoapServer(Mage::getUrl('*/*/*', array('wsdl' => 1))); use_soap_error_handler(false); $this->_soap->setClass($this->getHandler()); $this->getController()->getResponse()->setHeader('Content-Type', 'text/xml')->setBody($this->_soap->handle()); } else { $this->fault('0', 'Unable to load Soap extension on the server'); } return $this; }
// Ustawienie uprawnień użytkownika/grupy "www-data" $posixInfo = posix_getpwnam('www-data'); if ($posixInfo !== false) { posix_setgid($posixInfo['gid']); posix_setuid($posixInfo['uid']); } require_once 'defines.php'; require_once MK_PATH . DIRECTORY_SEPARATOR . 'functions.php'; require_once MK_PATH . DIRECTORY_SEPARATOR . 'MK.php'; validate_directory(MK_DIR_TEMP); if (!defined('SESSION_SAVE_HANDLER') || SESSION_SAVE_HANDLER == 'files') { validate_directory(MK_DIR_SESSION); block_directory_htaccess(MK_DIR_SESSION); } spl_autoload_register('MK::_autoload'); use_soap_error_handler(MK_DEBUG); MK::checkApplicationState(); // wylaczenie cachowania wsdl'a ini_set("soap.wsdl_cache_enabled", WSDL_CACHE_ENABLE); // ustawienie strefy czasowej date_default_timezone_set(MK_TIMEZONE); // do polskich nazw dat w kalendarzu setlocale(LC_TIME, MK_LOCALE_TIME); // do "." w liczbach, a nie "," setlocale(LC_NUMERIC, MK_LOCALE_NUMERIC); if (MK_DEBUG || MK_IS_CLI) { error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 'on'); set_time_limit(0); umask(0); // Resetowanie maski uprawnien
/** * __sendSOAPNFSe * Estabelece comunicaçao com servidor SOAP 1.1 ou 1.2 da SEFAZ, * usando as chaves publica e privada parametrizadas na contrução da classe. * Conforme Manual de Integração Versão 4.0.1 * * @param $urlwebservice * @param string $cabecalho * @param string $dados * @param string $metodo * @param int $ambiente * @version 1.0 * @package NFePHP * @return mixed False se houve falha ou o retorno em xml do SEFAZ */ private function __sendSOAPNFSe($urlwebservice, $cabecalho, $dados, $metodo, $ambiente) { use_soap_error_handler(TRUE); if ($ambiente == 1) { $ambiente = 'producao'; $URL = $urlwebservice . '?wsdl'; } else { $ambiente = 'homologacao'; $URL = $urlwebservice . '?wsdl'; } $soapver = SOAP_1_1; $options = array('encoding' => 'UTF-8', 'verifypeer' => FALSE, 'verifyhost' => FALSE, 'soap_version' => $soapver, 'style' => SOAP_DOCUMENT, 'use' => SOAP_LITERAL, 'local_cert' => $this->certKEY, 'trace' => TRUE, 'compression' => 0, 'exceptions' => TRUE, 'cache_wsdl' => WSDL_CACHE_NONE); //instancia a classe soap try { $oSoapClient = new NFSeSOAPClient($URL, $options); } catch (Exception $e) { $this->errStatus = TRUE; $this->errMsg = $e->__toString(); return FALSE; } //faz a chamada ao metodo do webservices try { // não precisa enviar cabecalho... $varBody = $dados; $aBody = array("", "loteXML" => $varBody); $resp = $oSoapClient->__soapCall($metodo, $aBody); $resposta = $oSoapClient->__getLastResponse(); $this->soapRequest = $oSoapClient->soapRequest; } catch (Exception $e) { $this->soapRequest = $oSoapClient->soapRequest; $this->errStatus = TRUE; $this->errMsg = $e->__toString(); return FALSE; } $this->soapDebug = $oSoapClient->__getLastRequestHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastRequest(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponseHeaders(); $this->soapDebug .= "\n" . $oSoapClient->__getLastResponse(); return $resposta; }
function gs_get_soap_client($api, $service, $host) { try { if (!in_array($api, array('m01', 'm02'), true)) { gs_log(GS_LOG_WARNING, 'Invalid foreign host API "' . $api . '"'); return false; } switch ($service) { case 'guiintegration': $path = '/soap/guiServer.php'; break; case 'generatecall': $path = '/soap/callServer.php'; break; case 'updateextension': $path = '/soap/extensionServer.php'; break; default: return false; } use_soap_error_handler(false); $use_ssl = _gs_boi_ssl_is_possible($host); $SoapClient = null; $url = ($use_ssl ? 'https' : 'http') . '://' . $host . $path; $SoapClient = new SoapClient(dirName(__FILE__) . '/wsdl/' . $service . '-' . $api . '.wsdl', array('location' => $url, 'soap_version' => SOAP_1_2, 'login' => null, 'password' => null, 'proxy_host' => null, 'proxy_port' => null, 'proxy_login' => null, 'proxy_password' => null, 'local_cert' => $use_ssl ? '/etc/apache2/conf.d/ssl/gemeinschaft_provisioning_client.pem' : null, 'passphrase' => null, 'encoding' => 'UTF-8', 'compression' => null, 'trace' => false, 'exceptions' => true, 'connection_timeout' => 6, 'user_agent' => 'Gemeinschaft', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS)); gs_log(GS_LOG_DEBUG, 'SOAP call to ' . $url); return $SoapClient; } catch (SOAPFault $SoapFault) { //echo 'SOAP error: ', $SoapFault->faultstring ,"\n"; //print_r($SoapFault); gs_log(GS_LOG_WARNING, 'SOAP error: ' . $SoapFault->faultstring . ' (' . @$SoapFault->faultcode . ')'); return false; } }
/** * Lets the native PHP5 soap implementation handle the request * after registrating the class. */ private function handleRequest() { //check if it's a legal webservice class if (!in_array($this->name, $this->classNameArr)) { throw new Exception('No valid webservice class.'); } //check cache if (!file_exists($this->wsdlfile)) { $this->createWSDL(); } $options = array('soap_version' => SOAP_1_1, 'actor' => $this->actor, 'classmap' => $this->structureMap); header('Content-type: text/xml'); $this->server = new SoapServer($this->wsdlfile, $options); $this->server->setClass($this->name); $this->server->setPersistence($this->persistence); use_soap_error_handler(true); $this->server->handle(); }
// watchdog('mpay_integration', 'IN Request, HTTP_RAW_POST_DATA: @HTTP_RAW_POST_DATA php_input: @php_input', array('@HTTP_RAW_POST_DATA'=>$GLOBALS['HTTP_RAW_POST_DATA'], '@php_input'=>file_get_contents('php://input')), WATCHDOG_DEBUG); if (variable_get('mpay_integration_enable_ip_filter', FALSE)) { $ip = explode("\n", variable_get('mpay_integration_allowed_ip', '')); if (!in_array(ip_address(), $ip)) { header('HTTP/1.0 403 Forbidden'); exit; } } $module_path = drupal_get_path('module', 'mpay_integration'); include_once DRUPAL_ROOT . "/{$module_path}/soap/mpayServer.class.inc"; include_once DRUPAL_ROOT . "/{$module_path}/soap/server.api.inc"; include_once DRUPAL_ROOT . "/{$module_path}/soap/signer.api.inc"; include_once DRUPAL_ROOT . "/{$module_path}/libraries/soap-server-wsse.php"; include_once DRUPAL_ROOT . "/{$module_path}/libraries/soap-wsse.php"; include_once DRUPAL_ROOT . "/{$module_path}/libraries/soap-wsa.php"; use_soap_error_handler(TRUE); $drupal_url = preg_replace(DRUPAL_MODULE_ROOT_RE, '', $base_url); $service_url = $drupal_url . '/mpay/payment-interface?wsdl'; $wsdl_path = get_wsdl_path($service_url); $server = new SoapServerExt($wsdl_path); $server->setClass("mpayServer"); ob_start(); $server->handle(); $soapResponse = ob_get_contents(); ob_end_clean(); header('HTTP/1.1 200 OK'); if (empty($GLOBALS['HTTP_RAW_POST_DATA']) && !file_get_contents('php://input')) { //request for receive wsdl echo $soapResponse; exit; }