#php #soap #namespaces
Вопрос:
Я довольно новичок в API-интерфейсах SOAP и мог бы воспользоваться некоторой помощью в этом сценарии. У меня есть некоторый PHP-код (ниже), который создает этот XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://www.transporeon.com/Attachment.Interface/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.transporeon.com/Attachment.Interface">
<SOAP-ENV:Header>
<ns2:TisysHeader>
<ns1:CompanyId>123</ns1:CompanyId>
<ns1:Username>ABC</ns1:Username>
<ns1:Password>***</ns1:Password>
</ns2:TisysHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:UploadAttachment>
<Attachment>
<ns1:TransportId>123</ns1:TransportId>
<ns1:DeliveryNumber></ns1:DeliveryNumber>
<ns1:Qualifier>attachment.type.billoflading</ns1:Qualifier>
<ns1:Description></ns1:Description>
<ns1:Filename>BOL_TEST.png</ns1:Filename>
<ns1:Data></ns1:Data>
</Attachment>
<SchedulerEmail></SchedulerEmail>
</ns1:UploadAttachment>
<param1/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Но мне нужно, чтобы <Вложение><Вложение> было <ns2:Вложение><ns2:Вложение>, чтобы вызов SOAP был успешным. Как я могу это сделать? Вот мой PHP-код:
<?php
/* ~~~~~
Config
~~~~~ */
$transporeon_shipment_id = 123;
$test_file = 'path to random image';
/* ~~~~~
Create Classes
~~~~~ */
if (! class_exists("TisysHeader")){
class TisysHeader {
function __construct() {
$this->CompanyId = 123;
$this->Username = 'ABC';
$this->Password = '***';
}
}
}
if (! class_exists("UploadAttachment")){
class UploadAttachment {
function __construct( $Attachment, $SchedulerEmail ) {
$this->Attachment = $Attachment;
$this->SchedulerEmail = $SchedulerEmail;
}
}
}
if (! class_exists("Attachment")){
class Attachment {
function __construct( $TransportId, $DeliveryNumber, $Qualifier, $Description, $Filename, $Data ) {
$this->TransportId = $TransportId;
$this->DeliveryNumber = $DeliveryNumber;
$this->Qualifier = $Qualifier;
$this->Description = $Description;
$this->Filename = $Filename;
$this->Data = $Data;
}
}
}
/* ~~~~~
Do SOAP Call
~~~~~ */
$SoapClient = new SoapClient('https://xch.transporeon.com/carrier_interface/attachment?wsdl',array('trace' => 1));
$TisysHeader = new TisysHeader();
$header = new SoapHeader('http://www.transporeon.com/Attachment.Interface', 'TisysHeader', $TisysHeader);
$SoapClient->__setSoapHeaders($header);
$base64_file = base64_encode(file_get_contents($test_file));
$Attachment = new Attachment( $transporeon_shipment_id, "", 'attachment.type.billoflading', "", "BOL_TEST.png", $base64_file );
$UploadAttachment = new UploadAttachment( $Attachment, "" );
$soap_response = $SoapClient->UploadAttachment( $UploadAttachment, $params=[] );
?>
Есть какие-нибудь идеи о том, как это сделать? Я не совсем уверен, как присоединить пространство имен к элементу SOAP.
Любая помощь будет очень признательна!