我有要使用的服务SOAP。该Web服务可在SoapUI上使用,而不能在我的PHP代码中使用。
我尝试从中发送XML或从中发送XML,但是两者均无法正常工作。
如果我通过其他功能发送不带CDATA参数的XML,则它正常工作。
<?php
$url = 'https://url/Service.svc?WSDL';
$contextOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$stream_context = stream_context_create($contextOptions);
$client = new SoapClient($url, array(
'cache_wsdl' => WSDL_CACHE_NONE,
'exceptions' => 1,
'trace' => 1,
'stream_context' => $stream_context,
'soap_version' => SOAP_1_1,
'use' => SOAP_LITERAL,
'style' => SOAP_DOCUMENT
));
try
{
$xml1 = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GET_BALANCE>
<!--Optional:-->
<tem:requestXML><![CDATA[
<Request>
<MERCHANTID>199191</MERCHANTID>
<PASSWORD>FAkepass</PASSWORD>
<TXID>393993</TXID>
<LOCALDATETIME>20190211100000</LOCALDATETIME>
<TERMINALID>2828282</TERMINALID>
<IMEI>1234567890201</IMEI>
</Request>
]]></tem:requestXML>
</tem:GET_BALANCE>
</soapenv:Body>
</soapenv:Envelope>';
$args = array(
new SoapVar($xml1, XSD_ANYXML)
);
$res = $client->__soapCall('GET_BALANCE', $args);
var_dump($res);
}
catch(SoapFault $e)
{
echo "Error: {$e}";
}
echo "<hr>Last Request";
echo "<pre>", htmlspecialchars($client->__getLastRequest()) , "</pre>";
}