我有这个 wsdl由 SoapUI 生成的 xml :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:safetypay:mws:api:messages">
<soapenv:Header/>
<soapenv:Body>
<urn:CommunicationTestRequest>
<urn:ApiKey>?</urn:ApiKey>
<urn:RequestDateTime>?</urn:RequestDateTime>
<urn:Signature>?</urn:Signature>
</urn:CommunicationTestRequest>
</soapenv:Body>
</soapenv:Envelope>
它工作正常,但是当我使用 PHP 客户端 SoapClient 创建它时,它失败了......我发现错误是因为它略有不同,它只是缺少骨灰盒(我不知道它是什么)。SoapClient 的 xml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<CommunicationTestRequest>
<RequestDateTime>2012-04-17T23:21:54</RequestDateTime>
<ApiKey>XXXXX</ApiKey>
<Signature>XXXXX</Signature>
</CommunicationTestRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
三个主要区别是:1)在定义中,SoapClient 生成的代码缺少这个: xmlns:urn="urn:safetypay:mws:api:messages" 2)在 SoapUI 生成的 xml 中我有soapenv,而在SoapClient 生成的那个是 SOAP-ENV 3)在 SoapUI 中,我在每个孩子之前都有瓮,SoapClient 没有。
我几乎一整天都在更改配置并从对象向后移动到数组(因为过去它与其他 wsdl 一起使用),而我在互联网上的研究并没有给我任何东西......所以......任何人都可以知道我的错误是什么吗?
请求是这样的:
$std = new RequestDateTime();
$std->RequestDateTime = date ( 'Y-m-d\TH:i:s', time () );
$std->ApiKey = SafetyPaySoap::API_KEY_SAND;
$std->Signature = SafetyPaySoap::SIG_KEY_SAND;
$this->_wsdl->CommunicationTest($std);
SoapClient 的配置是这个
$config = array ();
$config ['exceptions'] = true;
$config ['trace'] = true;
$config ['cache_wsdl'] = WSDL_CACHE_NONE;
$config ['soap_version'] = SOAP_1_1;
parent::SoapClient ( $url . '?wsdl', $config );
编辑: 我能够修复这个错误。我不得不重写 __doRequest 方法。现在看起来像这样:
public function __doRequest($request, $location, $action, $version, $one_way = null) {
$request = str_ireplace("<{$this->_method}Request>", "<{$this->_method}Request xmlns='urn:safetypay:mws:api:messages'>", $request);
return parent::__doRequest ( $request, $location, $action, $version, $one_way );
}
所以,我正在做的是在请求中添加命名空间,然后生成这个 xml:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<CommunicationTestRequest xmlns='urn:safetypay:mws:api:messages'>
<ApiKey>XXXX</ApiKey>
<RequestDateTime>2012-04-18T20:22:51</RequestDateTime>
<Signature>XXXXX</Signature>
</CommunicationTestRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>