Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('soap.wsdl_cache_enabled',0);
  4. ini_set('soap.wsdl_cache_ttl',0);
  5. ini_set('default_socket_timeout', 15);
  6. ini_set('default_socket_timeout', 1000);
  7.  
  8. class WsseAuthHeader extends SoapHeader
  9. {
  10. private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  11. private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
  12.  
  13. function __construct($user, $pass)
  14. {
  15. $created = gmdate('Y-m-dTH:i:sZ');
  16. $nonce = mt_rand();
  17. $passdigest = base64_encode(pack('H*', sha1(pack('H*', $nonce) . pack('a*', $created) . pack('a*', $pass))));
  18.  
  19. $auth = new stdClass();
  20. $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  21. $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  22. $auth->Nonce = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  23. $auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsu_ns);
  24.  
  25. $username_token = new stdClass();
  26. $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
  27.  
  28. $security_sv = new SoapVar(
  29. new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
  30. SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
  31. parent::__construct($this->wss_ns, 'Security', $security_sv, true);
  32. }
  33. }
  34.  
  35. # credencials
  36. $username = "XXXXX";
  37. $password = "XXXXXXXXX";
  38.  
  39. $checkVatParameters = array('fromDate' =>'XXXX' ,
  40. 'toDate' =>'XXXXX',
  41. );
  42.  
  43. $Values = new stdClass();
  44. $Values->User = new SoapVar($username, XSD_STRING, NULL, "", NULL, "");
  45. $Header = new SOAPHeader("urn:/microsoft/multichannelframework/", 'Values', $Values, true);
  46.  
  47. $options = array(
  48. 'uri'=>'http://schemas.xmlsoap.org/soap/envelope/',
  49. 'style'=>SOAP_RPC,
  50. 'use'=>SOAP_ENCODED,
  51. 'soap_version'=>SOAP_1_1,
  52. 'cache_wsdl'=>WSDL_CACHE_NONE,
  53. 'connection_timeout'=>300,
  54. 'trace'=>1,
  55. 'encoding'=>'UTF-8',
  56. 'exceptions'=>true,
  57. );
  58.  
  59. # request
  60. try {
  61. #print "1";
  62. $wsse_header = new WsseAuthHeader($username, $password);
  63. $soap = new SoapClient('XXXXXXXXX.wsdl', $options);
  64. $soap->__setSoapHeaders(array($Header,$wsse_header));
  65. $data = $soap->searchBatches($checkVatParameters);
  66. }
  67. catch(Exception $e) {
  68. // print "2";
  69. echo $soap->__getLastRequest();
  70. #print "<pre>" . print_r($soap,1) . "</pre>";
  71. die($e->getMessage());
  72. }
  73.  
  74. print "3";
  75. var_dump($data);
  76. die;
  77.  
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement