php SoapClient覆盖__dorequest在str_replace之后不会更改xml

时间:2017-03-17 11:16:54

标签: php soap

我重写了php SoapClient类,以便为元素添加属性。当我在发送之前打印更改的代码时,XML似乎按照假设进行了更改,但在通过__getLastRequest()查看XML时,XML似乎根本没有更改。在代码中我尝试向元素添加属性。也许有人知道为什么$ request_new XML字符串不会发送到服务器? (OutputXML()只是一些很好的格式化,以及对html的处理)

class SoapClientDebug extends SoapClient
{
    public function __doRequest($request, $location, $action, $version, $one_way = 0) {
        // change / add whatever needed
        $request_new = str_replace( '<env:Body', '<env:Body ns1:Id="TheBody"', $request );
        // debug out
        OutputXML($request_new);
        // calling parent
        return parent::__doRequest($request_new, $location, $action, $version, $one_way);
    }
}

在调用父__doRequest

之前检查输出的XML
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://logius.nl/digipoort/koppelvlakservices/1.2/" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://schemas.xmlsoap.org/soap/security/2000-12">
 <env:Header>
  <ns3:Security env:mustUnderstand="true">
   <ns2:Signature>
    <ns2:SignedInfo>
     <ns2:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
    <ns2:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
   <ns2:Reference>
    <ns2:Transforms>
     <ns2:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
    </ns2:Transforms>
   <ns2:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
  <ns2:DigestValue>$6hpmccmjxQmAI143OhQfIWpkryw=</ns2:DigestValue>
   </ns2:Reference>
  </ns2:SignedInfo>
 <ns2:SignatureValue>sv8n4h0rV4Xmbl+M+w+MLl7lVA8KFsoWRx5DqSKkwSie32jOFoJt0WvH6UWRQI</ns2:SignatureValue>
  <ns2:KeyInfo>
   <ns2:X509Data>
    <ns2:X509IssuerName>CN=TestSignCert</ns2:X509IssuerName>
     <ns2:X509SerialNumber>75496503122422458150193540449068096025</ns2:X509SerialNumber>
      </ns2:X509Data>
     </ns2:KeyInfo>
    </ns2:Signature>
   </ns3:Security>
  </env:Header>
 <env:Body ns1:Id="TheBody">
  <ns1:aanleverRequest>
   <ns1:berichtsoort>Omzetbelasting</ns1:berichtsoort>
    <ns1:aanleverkenmerk>Happyflow</ns1:aanleverkenmerk>
     <ns1:identiteitBelanghebbende>
      <ns1:nummer/>
     <ns1:type/>
    </ns1:identiteitBelanghebbende>
   <ns1:rolBelanghebbende>Intermediair</ns1:rolBelanghebbende>
    <ns1:berichtInhoud>
     <ns1:mimeType/>
    <ns1:bestandsnaam/>
   <ns1:inhoud/>
  </ns1:berichtInhoud>
 <ns1:autorisatieAdres>https://secure.inepd.nl/inloon</ns1:autorisatieAdres>
  </ns1:aanleverRequest>
 </env:Body>
</env:Envelope>

通过__getLastRequest审核XML

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://logius.nl/digipoort/koppelvlakservices/1.2/" xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://schemas.xmlsoap.org/soap/security/2000-12">
 <env:Header>
  <ns3:Security env:mustUnderstand="true">
   <ns2:Signature>
    <ns2:SignedInfo>
     <ns2:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
    <ns2:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
   <ns2:Reference>
    <ns2:Transforms>
     <ns2:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
    </ns2:Transforms>
   <ns2:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
  <ns2:DigestValue>$6hpmccmjxQmAI143OhQfIWpkryw=</ns2:DigestValue>
   </ns2:Reference>
  </ns2:SignedInfo>
 <ns2:SignatureValue>sv8n4h0rV4Xmbl+M+w+MLl7lVA8KFsoWRx5DqSKkwSie32jOFoJt0WvH6UWRQI</ns2:SignatureValue>
  <ns2:KeyInfo>
   <ns2:X509Data>
    <ns2:X509IssuerName>CN=TestSignCert</ns2:X509IssuerName>
     <ns2:X509SerialNumber>75496503122422458150193540449068096025</ns2:X509SerialNumber>
      </ns2:X509Data>
     </ns2:KeyInfo>
    </ns2:Signature>
   </ns3:Security>
  </env:Header>
 <env:Body>
  <ns1:aanleverRequest>
   <ns1:berichtsoort>Omzetbelasting</ns1:berichtsoort>
    <ns1:aanleverkenmerk>Happyflow</ns1:aanleverkenmerk>
     <ns1:identiteitBelanghebbende>
      <ns1:nummer/>
     <ns1:type/>
    </ns1:identiteitBelanghebbende>
   <ns1:rolBelanghebbende>Intermediair</ns1:rolBelanghebbende>
    <ns1:berichtInhoud>
     <ns1:mimeType/>
    <ns1:bestandsnaam/>
   <ns1:inhoud/>
  </ns1:berichtInhoud>
 <ns1:autorisatieAdres>https://secure.inepd.nl/inloon</ns1:autorisatieAdres>
  </ns1:aanleverRequest>
 </env:Body>
</env:Envelope>

1 个答案:

答案 0 :(得分:1)

我弄明白为什么,回答我自己的问题可能有点奇怪,但未来可能对某人有所帮助;事实证明,在这种情况下,__ getLastRequest()不是实际的最后一个请求。所以重写__doRequest是一个选项,但在这种情况下不要使用__getLastRequest!

相关问题