我在PHP中成为WSSE Soap Header。如何向UsernameToken标签添加属性?
我正在使用SoapVar创建标头
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Nonce = new SoapVar($encoded_nonce, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
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);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
Web服务的结果是“传递的元素不是SOAPElement或不是正确的UsernameToken”。之所以可能是错误的UsernameToken标签。我需要添加wsu:Id属性。
我的标头中的XML输出
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://system.erif.pl/ws/schemas" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<ns2:Security SOAP-ENV:mustUnderstand="1">
<ns2:UsernameToken>
<ns2:Username>username</ns2:Username>
<ns2:Password>lD25MlnmRXtxjT8I2cv0iMhb0yQ=</ns2:Password>
<ns2:Nonce>MTA5NDY2Nji5OA==</ns2:Nonce>
<ns2:Created>2019-01-12T09:19:43Z</ns2:Created>
</ns2:UsernameToken>
</ns2:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetReportRequest/>
</SOAP-ENV:Body>
UsernameToken标记应具有这样的属性
<wsse:UsernameToken wsu:Id="UsernameToken-1"
在SoapVar中为UernameToken添加属性的正确方法是什么?谢谢