【问题标题】:php SoapClient override __dorequest does not change xml after str_replacephp SoapClient 覆盖 __dorequest 在 str_replace 之后不会更改 xml
【发布时间】:2017-03-17 11:16:53
【问题描述】:

我重写了 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>

【问题讨论】:

    标签: php soap


    【解决方案1】:

    我知道为什么,回答我自己的问题可能有点奇怪,但也许它可能会在将来对某人有所帮助;事实证明 __getLastRequest() 在这种情况下不是实际的最后一个请求。所以覆盖 __doRequest 是一种选择,但在这种情况下不要使用 __getLastRequest!

    【讨论】:

      猜你喜欢
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多