Advertisement
samrox2006

meavise_exclui_empresa_soap.php

Dec 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.28 KB | None | 0 0
  1. <?php
  2. //$CNPJ=  "71598742";
  3. $CNPJ =  "62173620"; //CNPJ EMEPARS
  4.  
  5. // ESSE
  6. ///$CNPJ="59732586";
  7. ini_set("display_errors", "on");
  8. ini_set("max_execution_time", 60000);
  9. set_time_limit(60000);
  10. error_reporting(E_ALL);
  11. $ambiente = 'homol';
  12. class WsseAuthHeader extends SoapHeader {
  13.  
  14.  private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  15.  private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
  16.  
  17.  function __construct($user, $pass) {
  18.  
  19.   $created = gmdate('Y-m-d\TH:i:s\Z');
  20.   $nonce = mt_rand();
  21.   $passdigest = base64_encode( pack('H*', sha1( pack('H*', $nonce) . pack('a*',$created).  pack('a*',$pass))));
  22.  
  23.   $auth = new stdClass();
  24.   $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  25.   $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  26.   $auth->Nonce = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  27.   $auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsu_ns);
  28.  
  29.   $username_token = new stdClass();
  30.   $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
  31.  
  32.   $security_sv = new SoapVar(
  33.    new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
  34.    SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
  35.   parent::__construct($this->wss_ns, 'Security', $security_sv, true);
  36. }
  37. }
  38. if($ambiente == 'prod') {
  39.   $urlWsdl = 'https://services.serasaexperian.com.br/MeAviseProxy?wsdl';
  40.    $username = '51315811';
  41.   $password = '';
  42. } else {
  43.   $urlWsdl = 'https://serviceshomologa.serasaexperian.com.br/MeAviseProxy?wsdl';
  44.   $username = '94059045';
  45.   $password = '10203040';
  46. }
  47. $plano = 'Mensal';
  48. $modalidade = 'NaoAutomatica';
  49.   try {
  50.     $soapClient = new SoapClient($urlWsdl, array(
  51.       'exceptions' => true,
  52.       'trace' => true
  53.     ));
  54.     $soapClient->__setSoapHeaders(Array(new WsseAuthHeader($username, $password)));
  55.     if($ambiente == 'prod') {
  56.       $requestData = array( 'cnpj' => $CNPJ);
  57.     } else {
  58.       $requestData = array( 'cnpj' => $CNPJ );
  59.     }
  60.     print_r($requestData);
  61.     $response = $soapClient->excluirClienteDistribuidor($requestData);
  62.   echo'<pre>';
  63. print_r($response);
  64. echo'</pre><br>';
  65. //echo 'RESPOSTA ARRAY PHP: ';
  66. //print_r($response);
  67.  
  68.  
  69. //echo '<br>RESPOSTA ARRAY JSON: ';
  70. //$resposta_json = json_encode($response);
  71. //var_dump($resposta_json);
  72. //echo "<br>";
  73. //$MSG = isset($response->retorno->Mensagem);
  74. //echo "Menssagem Retorno do Array: ".$MSG;
  75.  
  76.  
  77. //$RazaoSocial = isset($response->dadosRelato->empresaConsultada->RazaoSocial) ? $response->dadosRelato->empresaConsultada->RazaoSocial : NULL;
  78.    
  79.  
  80.     if (isset($response->erros->Mensagem->Mensagem)){
  81.     $MSG = $response->erros->Mensagem->Mensagem;
  82.  
  83.     echo "Mensagem Retorno de ERRO: ".$MSG;
  84.     // VERIFICA SE TEM MSG DE RESPOSTA DE SUCESSO  , AO TENTAR CADASTRAR EMPRESA
  85.     }else if(isset($response->erros->Mensagem->Mensagem)){
  86.         $MSG = $response->retorno->Mensagem;
  87.         echo "Mensagem Retorno de Sucesso: ".$MSG;
  88.     }
  89.   }catch (SoapFault $exception) {
  90.   echo $exception->getMessage();
  91. }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement