Я написал класс, который помогает упростить генерацию SOAP XML для пакета Laravel .Вот класс:
<?php
namespace Mtownsend\CollectionXml\Soap;
use SoapClient;
/**
* Use the SoapFactory class to build a valid SOAP request
* but prevent it from making an actual request
* and capture the data it builds for use.
*/
class SoapFactory extends SoapClient
{
public $soapRequest;
public $soapLocation;
public $soapAction;
public $soapVersion;
public function __construct($wsdl, $options)
{
parent::__construct($wsdl, $options);
}
/**
* Build the SOAP xml string
* @param array $soapRootAndXml [$soapRoot => $xml]
* @return Mtownsend\CollectionXml\Soap\SoapFactory
*/
public function build(array $soapRootAndXml)
{
$this->ProcessXMLRequest($soapRootAndXml);
return $this;
}
/**
* Override the SoapClient __doRequest method.
*/
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$this->soapRequest = $request;
$this->soapLocation = $location;
$this->soapAction = $action;
$this->soapVersion = $version;
return ''; // Return a string value or the SoapClient throws an exception
}
/**
* A proxy for the getSoapRequest method.
* @return string
*/
public function getSoapXml()
{
return $this->getSoapRequest();
}
/**
* Return the SOAP request XML.
* @return string
*/
public function getSoapRequest()
{
return $this->soapRequest;
}
/**
* Return the SOAP request location url.
* @return string
*/
public function getSoapLocation()
{
return $this->soapLocation;
}
/**
* Return the SOAP request action.
* @return string
*/
public function getSoapAction()
{
return $this->soapAction;
}
/**
* Return the SOAP request version number.
* @return string
*/
public function getSoapVersion()
{
return $this->soapVersion;
}
}
Если вы хотите его использовать, сохраните содержимое в SoapFactory.php
и включите его в свой скрипт.
Далее, подготовьте ваш необработанный xml. Не пытайтесь SOAPify или что-либо еще .Сохраните его в переменной $xml_post_string
.
Возможно, вам придется изменить корень мыла, если он не работает.В прошлом я подключался к конечным точкам мыла, использующим xmlBody.
$soapRoot = 'xmlBody';
$soapFactory = new SoapFactory($soapUrl, ['trace' => 1]));
$soapXml = $soapFactory->build([$soapRoot => $xml_post_string])->getSoapXml();
Теперь вы можете попробовать вызов curl.
$headers = array(
"Host: airarabia.isaaviations.com",
"Content-Type: application/soap+xml; charset=utf-8",
"Content-Length: ".strlen($soapXml)
);
$url = $soapUrl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapXml);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$parser = simplexml_load_string($response);
print_r($parser);
С SOAP нет никаких гарантий, но попробуйтеи посмотри, получится ли это где-нибудь.