Advertisement
Guest User

eet SOAP

a guest
Oct 4th, 2016
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. require 'wse/soap-wsse.php';
  2.  
  3. define('PRIVATE_KEY', 'certifikaty/privat_key.pem');
  4. define('CERT_FILE', 'certifikaty/certifikat.pem');
  5. //require 'wse-php-master/soap-wsse.php';
  6. //define('PRIVATE_KEY', 'F:\\php\\EasyPHP-Devserver-16.1\\eds-www\\eet\\other\\01000004.p12');
  7. //define('CERT_FILE', 'F:\\php\\EasyPHP-Devserver-16.1\\eds-www\\eet\\other\\ca.cer.pem');
  8.  
  9. class MySoap extends SoapClient {
  10.  
  11.     public function __doRequest($request, $location, $saction, $version, $one_way = null) {
  12.         $doc = new DOMDocument('1.0');
  13.         $doc->loadXML($request);
  14.  
  15.         $objWSSE = new WSSESoap($doc);
  16.  
  17.         /* add Timestamp with no expiration timestamp */
  18.         //$objWSSE->addTimestamp();
  19.  
  20.         /* create new XMLSec Key using RSA SHA-1 and type is private key */
  21.         $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type' => 'private'));
  22.  
  23.         $objKey->passphrase = "eet";
  24.        
  25.         /* load the private key from file - last arg is bool if key in file (true) or is string (FALSE) */
  26.         $objKey->loadKey(PRIVATE_KEY, true);
  27.  
  28.         /* Sign the message - also signs appropraite WS-Security items */
  29.         $objWSSE->signSoapDoc($objKey, array("algorithm" => XMLSecurityDSig::SHA256));
  30.                  
  31.         /* Add certificate (BinarySecurityToken) to the message and attach pointer to Signature */
  32.         $token = $objWSSE->addBinaryToken(file_get_contents(CERT_FILE));
  33.         $objWSSE->attachTokentoSig($token);
  34.         return parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version, $one_way);
  35.     }
  36.  
  37. }
  38.  
  39. $wsdl = 'http://www.etrzby.cz/assets/cs/prilohy/EETServiceSOAP.wsdl';
  40.  
  41. try {
  42.     $sClient = new MySoap($wsdl, array('trace' => 1));
  43.     /* Force location path - MUST INCLUDE trailing slash
  44.       BUG in ext/soap that does not automatically add / if URL does not contain path cause POST header to be invalid */
  45.  
  46.     $pkp = base64_decode("W7UlA4hXNsDLvCj/eeRAYeOAsNsgMSdltcJNIW98KQRsfspTMW0Lr/OGQgRHZfO5KjolZgzN3k9mgzrVoX2+N90fCNEnOri2kjrW5vzTgMK6OZ9IryAEg0xFZjjjCQ0qKsQsVi8OLQOn3ZnN/BUGG2SIduER+iIOrhfOmes7OXaa5/2jQSfPTHZHZ/Bxhqld3gL4PHvd7sevZYUupHpE1fM7Uw1+lu8i1YOdghZoMyOfKw7FcqvRJpHrW/JZL5Dr5iCgu5ClmhZrb3hZavsxlDG7P2cUhSQgmEVTxJ2n38q/Cf91KE8e52SODN4Q8BfncXpmtkQ7Go3KsRsY3xN7xg==");
  47.  
  48.     $test = $sClient->OdeslaniTrzby([
  49.     "Hlavicka" => [
  50.         "dat_odesl" => "2016-09-19T19:06:37+01:00",
  51.         "prvni_zaslani" => "false",
  52.         "uuid_zpravy" => "9edeb22b-4234-4047-869c-3a76f86c20d3"],
  53.     "Data" => [
  54.         "celk_trzba" => "34113.00",
  55.         "cerp_zuct" => "679.00",
  56.         "cest_sluz" => "5460.00",
  57.         "dan1" => "-172.39",
  58.         "dan2" => "-530.73",
  59.         "dan3" => "975.65",
  60.         "dat_trzby" => "2016-01-05T00:30:12+01:00",
  61.         "dic_popl" => "CZ00000019",
  62.         "id_pokl" => "/5546/RO24",
  63.         "id_provoz" => "273",
  64.         "porad_cis" => "0/6460/ZQ42",
  65.         "pouzit_zboz1" => "784.00",
  66.         "pouzit_zboz2" => "967.00",
  67.         "pouzit_zboz3" => "189.00",
  68.         "rezim" => "0",
  69.         "urceno_cerp_zuct" => "324.00",
  70.         "zakl_dan1" => "-820.92",
  71.         "zakl_dan2" => "-3538.20",
  72.         "zakl_dan3" => "9756.46",
  73.         "zakl_nepodl_dph" => "3036.00"
  74.     ],
  75.     "KontrolniKody" => [
  76.         "pkp" => ["cipher" => "RSA2048", "digest" => "SHA256", "encoding" => "base64", "_" => $pkp],
  77.         "bkp" => ["digest" => "SHA1", "encoding" => "base64", "_" => "1F1A2D90-4EAD34A8-411CFB0B-EB17616E-B2CE8114"]
  78.     ]
  79.         ]);
  80.    
  81.     $request = $sClient->__getLastRequest();  
  82.                  
  83. header("Content-type: text/xml");
  84.  
  85. echo $request;
  86.  
  87.  
  88.    
  89.     var_dump($test);
  90. } catch (SoapFault $e) {
  91.     var_dump($e);
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement