1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| <?php
class WsseSoapWebserviceClient extends SoapClient {
const SOAP_NAMESPACE = 'http://schemas.xmlsoap.org/soap/envelope/';
const WSSE_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
const WSU_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
const NONCE_ENCODING_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary';
const PASSWORD_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest';
var $username;
var $password;
var $prefix;
function __construct($wsdlUrl, $username, $password, $prefix = null, $options = array()) {
parent::__construct($wsdlUrl, $options);
$this->username = $username;
$this->password = $password;
$this->prefix = $prefix == null ? php_uname('n') : $prefix;
}
function __doRequest($request, $location, $action, $version, $one_way = null) {
$nonce = base64_encode(substr(md5(uniqid($this->prefix.'_', true)), 0, 20));
$timestampRfc8601 = (new DateTime("now", new DateTimeZone('UTC')))->format('Y-m-d\TH:i:s\Z');
$xml = new DOMDocument();
$xml->loadXML($request);
$xpath = new DOMXPath($xml);
$xpath->registerNamespace('SOAP-ENV', self::SOAP_NAMESPACE);
$headerElement = $xpath->query('/SOAP-ENV:Envelope/SOAP-ENV:Header')->item(0);
if (!$headerElement) {
$headerElement = $xml->createElementNS(self::SOAP_NAMESPACE, 'SOAP-ENV:Header');
$envelopeElement = $xpath->query('/SOAP-ENV:Envelope')->item(0);
$bodyElement =$xpath->query('/SOAP-ENV:Envelope/SOAP-ENV:Body')->item(0);
$envelopeElement->insertBefore($headerElement, $bodyElement);
}
$passwordElement = $xml->createElementNS(self::WSSE_NAMESPACE, 'wsse:Password', base64_encode(sha1(base64_decode($nonce).$timestampRfc8601.$this->password, true)));
$passwordElement->setAttribute('Type', self::PASSWORD_TYPE);
$nonceElement = $xml->createElementNS(self::WSSE_NAMESPACE, 'wsse:Nonce', $nonce);
$nonceElement->setAttribute('EncodingType', self::NONCE_ENCODING_TYPE);
$usernameTokenElement = $xml->createElementNS(self::WSSE_NAMESPACE, 'wsse:UsernameToken');
$usernameTokenElement->appendChild($xml->createElementNS(self::WSSE_NAMESPACE, 'wsse:Username', $this->username));
$usernameTokenElement->appendChild($passwordElement);
$usernameTokenElement->appendChild($nonceElement);
$usernameTokenElement->appendChild($xml->createElementNS(self::WSU_NAMESPACE, 'wsu:Created', $timestampRfc8601));
$securityElement = $xml->createElementNS(self::WSSE_NAMESPACE, 'wsse:Security');
$securityElement->appendChild($usernameTokenElement);
$headerElement->appendChild($securityElement);
$request = $xml->saveXML();
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
}
class KeyValuePair {
public $key;
public $value;
function __construct($key, $value) {
$this->key = new SoapVar($key, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
$this->value = new SoapVar($value, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
}
}
?>
|
54055(+98) Besucher