Advertisement
Guest User

Untitled

a guest
Apr 4th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2.  
  3. class WsseAuthHeader extends SoapHeader {
  4. private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  5.  
  6. function __construct($user, $pass, $ns = null) {
  7. if ($ns) {
  8. $this->wss_ns = $ns;
  9. }
  10.  
  11. $auth = new stdClass();
  12. $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  13. $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  14.  
  15. $username_token = new stdClass();
  16. $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
  17.  
  18. $security_sv = new SoapVar(
  19. new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
  20. parent::__construct($this->wss_ns, 'Security', $security_sv, true);
  21. }
  22.  
  23. }
  24.  
  25. $username = 'login';
  26. $password = 'pass';
  27. $wsdl = 'url';
  28.  
  29. $wsse_header = new WsseAuthHeader($username, $password);
  30.  
  31. $client = new SoapClient($wsdl, array(
  32. "trace" => 0,
  33. 'soap_version' => SOAP_1_2,
  34. "exceptions" => 0,
  35. )
  36. );
  37.  
  38. $client->__setSoapHeaders(array($wsse_header));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement