i want to send a soap request using php but i found a problem here is what i have to send as XML format.
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:getImpayee>
<tem:tocken>reererer</tem:tocken>
<tem:CodeCreancier>1013</tem:CodeCreancier>
<tem:CodeCreance>01</tem:CodeCreance>
<tem:crVals>
<tem:CreancierVals>
<tem:nomChamp>montant</tem:nomChamp>
<tem:ValeurChamp>45</tem:ValeurChamp>
</tem:CreancierVals>
<tem:CreancierVals>
<tem:nomChamp>ND</tem:nomChamp>
<tem:ValeurChamp>0663143327</tem:ValeurChamp>
</tem:CreancierVals>
</tem:crVals>
</tem:getImpayee>
</soap:Body>
</soap:Envelope>
but the problem is that there is multiple "tem:CreancierVals" when i use this
$client->__setLocation(url_PaiementWS);
$result = $client->getImpayee(
array(
'tocken' => $_SESSION['tocken'],
'CodeCreancier' => $CodeCreancier,
'CodeCreance' => $CodeCreance,
'crVals' => array (
'CreancierVals' => array(
'nomChamp' => 'montant',
'ValeurChamp' => $montant
),
'CreancierVals' => array(
'nomChamp' => 'ND',
'ValeurChamp' => $ND
)
)
)
);
it doesnt work
its like reseting the "CreancierVals" val
is there a solution in which i can send pure xml using php ? or just a dynamic method that doesn't reseting the "CreancierVals" val but add one to the other as an array for example. thanks
Try this:
$result = $client->getImpayee(
[
'tocken' => $_SESSION['tocken'],
'CodeCreancier' => $CodeCreancier,
'CodeCreance' => $CodeCreance,
'crVals' => [
'CreancierVals' => [
[
'nomChamp' => 'montant',
'ValeurChamp' => $montant,
],
[
'nomChamp' => 'ND',
'ValeurChamp' => $ND,
],
],
],
]
);
Related
I am trying to make a SOAP call in PHP while I am trying to pass some parameters some of them are never sent. I do not really know if it is a problem about building the LoginYInsertarEvento2Params object or it is more related about the soap call.
This is the object that I build for making the call
$LoginYInsertarEvento2Params = array(
"SystemUser" => "XXXXX",
"Password" => "XXXXXX",
"Dominio" => $registration,
"NroSerie" => $terminal_serial,
"Codigo" => "",
"Latitud" => $latitude,
"Longitud" => $longitude,
"Altitud" => "0",
"Velocidad" => $speed,
"FechaHoraEvento" => date('c', strtotime($fecha_evento)),
"FechaHoraRecepcion" => date('c', strtotime($fecha_registro)),
"Valido" => true,
"Sensores" =>array ( ["Temperatura" => $temp], ["Luminosidad" => $lum] )
);
This the request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="XXXXXXXXXXXXXXXXXXX">
<SOAP-ENV:Body>
<ns1:LoginYInsertarEvento2>
<ns1:SystemUser>XXXXX</ns1:SystemUser>
<ns1:Password>XXXXX</ns1:Password>
<ns1:Dominio>XXXXXX</ns1:Dominio>
<ns1:NroSerie>-1</ns1:NroSerie>
<ns1:Codigo></ns1:Codigo>
<ns1:Latitud>40.348054</ns1:Latitud>
<ns1:Longitud>-3.681576</ns1:Longitud>
<ns1:Altitud>0</ns1:Altitud>
<ns1:Velocidad>0</ns1:Velocidad>
<ns1:FechaHoraEvento>2020-10-09T12:50:40+02:00</ns1:FechaHoraEvento>
<ns1:FechaHoraRecepcion>2020-10-09T12:50:56+02:00</ns1:FechaHoraRecepcion>
<ns1:Valido>true</ns1:Valido>
<ns1:Sensores>
<ns1:pSensor/>
<ns1:pSensor/>
</ns1:Sensores>
</ns1:LoginYInsertarEvento2>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And it should be like this one...
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<LoginYInsertarEvento2 xmlns="http://unisolutions.com.ar/">
<SystemUser>XXXXXX</SystemUser>
<Password>xxxxxxxx</Password>
<Dominio>XXXXXXX</Dominio>
<NroSerie>-1</NroSerie>
<Codigo />
<Latitud>41.748311</Latitud>
<Longitud>-0.848768</Longitud>
<Altitud>274</Altitud>
<Velocidad>0</Velocidad>
<FechaHoraEvento>2020-10-06T09:36:56</FechaHoraEvento>
<FechaHoraRecepcion>2020-10-06T09:36:56</FechaHoraRecepcion>
<Valido>true</Valido>
<Sensores>
<pSensor>
<Clave>Temperatura</Clave>
<Valor>11.6</Valor>
</pSensor>
<pSensor>
<Clave>Luminosidad</Clave>
<Valor>0</Valor>
</pSensor>
</Sensores>
</LoginYInsertarEvento2>
</s:Body>
</s:Envelope>
Thanks guys!
Judging by what you expect your output to be. Try changing the structure to look like this:
$LoginYInsertarEvento2Params = array(
"SystemUser" => "XXXXX",
"Password" => "XXXXXX",
"Dominio" => $registration,
"NroSerie" => $terminal_serial,
"Codigo" => "",
"Latitud" => $latitude,
"Longitud" => $longitude,
"Altitud" => "0",
"Velocidad" => $speed,
"FechaHoraEvento" => date('c', strtotime($fecha_evento)),
"FechaHoraRecepcion" => date('c', strtotime($fecha_registro)),
"Valido" => true,
"Sensores" =>array (
["Clave" => "Temperatura", "Valor" => $temp],
["Clave" => "Luminosidad", "Valor" => $lum]
)
);
I may be wrong, but it just looks like the Sensores structure is incorrect.
I'm using PHP and have to build a SOAP (1.1, Document/Literal) request that contains a XML message inside soap:Body tag.
My first issue is that I'd never used this "protocol" before.
My XML message is quite complex so I'm using SimpleXMLElement class to build it separately. To compose the SOAP message, I have two XML strings:
1- The SOAP structure.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header></soap:Header>
<soap:Body>...</soap:Body>
</soap:Envelope>
2- My Custom XML String
<eSocial xmlns="http://www.esocial.gov.br/schema/lote/eventos/envio/v2_2_02" grupo="1">
<envioLoteEventos>
<ideEmpregador tpInsc="1" nrInsc="0000000012"/>
<ideTransmissor tpInsc="1" nrInsc="0000000012"/>
<eventos>
<eSocial xmlns="http://www.esocial.gov.br/schema/evt/evtInfoEmpregador/v2_2_02">
<evtInfoEmpregador Id="8515">...</evtInfoEmpregador>
</eSocial>
</eventos>
</envioLoteEventos>
</eSocial>
What I need: The second string inside soap:Body tag exactly as it is.
What I get: The second string inside soap:Body with a bunch of namespaces automatically added by DOMDocument.
The algorithm (not full code) that I'm using:
$soapBodyElement = new SimpleXMLElement($soapBodyString);
$customMessageElement = new SimpleXMLElement($customMessageString);
// Some operations...
$domParent = dom_import_simplexml($soapBodyElement);
$domChild = dom_import_simplexml($customMessageElement);
$domDocument = $domParent->ownerDocument->importNode($domChild, true);
$domParent->appendChild($domDocument);
echo $domParent->ownerDocument->saveXML();
Output:
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<eSocial xmlns="http://www.esocial.gov.br/schema/lote/eventos/envio/v2_2_02" xmlns:default="http://www.esocial.gov.br/schema/evt/evtInfoEmpregador/v2_2_02" xmlns:default1="http://www.w3.org/2000/09/xmldsig#" grupo="1">
<envioLoteEventos>
<ideEmpregador tpInsc="1" nrInsc="0000000012"/>
<ideTransmissor tpInsc="1" nrInsc="0000000012"/>
<eventos>
<default:eSocial xmlns="http://www.esocial.gov.br/schema/evt/evtInfoEmpregador/v2_2_02">
<default:evtInfoEmpregador Id="2550">...</default:evtInfoEmpregador>
</default:eSocial>
</eventos>
</envioLoteEventos>
</eSocial>
</soap:Body>
</soap:Envelope>
Honestly, I don't know why this default prefixes (namespaces?) were added.
How can I append two XML strings without this automatic behavior?
You could use the Marshal XML Serializer which is much easier to use then DOMDocument and SimpleXML.
Then you could do the following:
SoapEnvelopeMapper.php
use KingsonDe\Marshal\AbstractXmlMapper;
class SoapEnvelopeMapper extends AbstractXmlMapper {
/**
* #var AbstractXmlMapper
*/
private $messageMapper;
public function __construct(AbstractXmlMapper $messageMapper) {
$this->messageMapper = $messageMapper;
}
public function map($data) {
return [
'soap:Envelope' => [
$this->attributes() => [
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xmlns:soap' => 'http://www.w3.org/2003/05/soap-envelope',
],
'soap:Header' => null,
'soap:Body' => $this->item($this->messageMapper, $data),
]
];
}
}
SoapMessageMapper.php
use KingsonDe\Marshal\AbstractXmlMapper;
class SoapMessageMapper extends AbstractXmlMapper {
public function map($data) {
return [
'eSocial' => [
$this->attributes() => [
'xmlns' => 'http://www.esocial.gov.br/schema/lote/eventos/envio/v2_2_02',
'xmlns:default' => 'http://www.esocial.gov.br/schema/evt/evtInfoEmpregador/v2_2_02',
'xmlns:default1' => 'http://www.w3.org/2000/09/xmldsig#',
'grupo' => 1,
],
'envioLoteEventos' => [
'ideEmpregador' => [
$this->attributes() => [
'tpInsc' => 1,
'nrInsc' => '0000000012',
],
],
'ideTransmissor' => [
$this->attributes() => [
'tpInsc' => 1,
'nrInsc' => '0000000012',
],
],
],
'eventos' => [
'eSocial' => [
$this->attributes() => [
'xmlns' => 'http://www.esocial.gov.br/schema/evt/evtInfoEmpregador/v2_2_02',
],
'evtInfoEmpregador' => [
$this->attributes() => [
'Id' => 2550,
],
$this->data() => '...',
],
],
],
]
];
}
}
SoapResponse.php
$data = new \stdClass();
$messageMapper = new SoapMessageMapper();
$envelopeMapper = new SoapEnvelopeMapper($messageMapper);
$xml = MarshalXml::serializeItem($envelopeMapper, $data);
I'm trying to create this XML in a SOAP call
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1">
<ns2:membershipType>PFS</ns2:membershipType>
<ns2:membershipNumber>222222E</ns2:membershipNumber>
<ns2:membershipLevel>SILVER</ns2:membershipLevel>
<ns2:memberName>Luis Fernandez </ns2:memberName>
</ns1:NameMembership>
I don't know how to add the primarykey and displaySequence` attributes. I trying to create something like this:
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array("_" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E"), "primary" => true, "displaySequence" => 1
));
But it doesn't work. It returns this code:
<ns1:InsertGuestCardRequest>
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1"/>
</ns1:InsertGuestCardRequest>
Can anyone help me to find what am I doing wrong?
I got it! Thanks!
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E",
"primary" => true,
"displaySequence" => 1
));
I got an issue here. I am trying make a request to a Web Appi: http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL
And I am sending a request to insertPodData();
I am using PHP and SOAP.
I am succesfull at connecting and giving the correct credentials. However I am not able to send a Dataset (cause I do not know the right way), so i get an empty dataset.
Datasets are for .NET lang. So it is kind of tricky with the php.
I tried already to send it as an array, i still get an empty result.
Here are some coding.
PHP:
$dataset = array(
'schema' => array(
'Enter_Branch_Id' => $speedex_branch_id,
'SND_Customer_Id' => $speedex_cust_id,
'SND_Agreement_Id' => $speedex_appi_key,
'RCV_Name' => 'Test',
'RCV_Addre1' => 'Test Adress',
'RCV_Zip_Code' => '54636',
'RCV_City' => 'Thessaloniki',
'RCV_Country' => 'Greece',
'RCV_Tel1' => '*******',
'Voucher_Weight' => '0',
),
'any' => ''
);
try {
$soap = new SoapClient("http://www.speedex.gr/getvoutrans/getvoutrans.asmx?WSDL",array('trace' => true));
$oAuthResult = $soap->insertPodData(
array(
'username' => $speedex_usrn,
'password' => $speedex_psw,
'VoucherTable' => $dataset,
'_tableFlag' => 3
)
);
$resultVoucher = $oAuthResult;
print_r($resultVoucher);
echo '<br>';
echo "REQUEST:\n" . htmlentities($soap->__getLastRequest()) . "\n";
die();
}catch(SoapFault $fault) {
die('<h1>Ooooops something is broken. Refresh or contact module creator </h1><br>'.$fault);
}
This is returning this result
RESULT: stdClass Object ( [insertPodDataResult] => 1 [newVoucherTable] => stdClass Object ( [schema] => [any] => ) )
REQUEST:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:insertPodData>
<ns1:username>****</ns1:username>
<ns1:password>****</ns1:password>
<ns1:VoucherTable>********************TestTest Adress54636ThessalonikiGreece********</ns1:VoucherTable>
<ns1:_tableFlag>3</ns1:_tableFlag>
</ns1:insertPodData>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
As you can observe the Dataset is not created and all the values are passed with out a reference.
Any ideas clues? Thanks in advance!
I never worked with SOAP XML api before.
I read a couple of similar questions on SO but I can't get it to work.
Here's a simple request:
<soap12:Envelope xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:xsd=”http://www.w3.org/2001/XMLSchema” xmlns:soap12=”http://www.w3.org/2003/05/
soap-envelope”>
<soap12:Body>
<CheckDomainAvailability xmlns=”https://live.domainbox.net/”>
<AuthenticationParameters>
<Reseller>myreseller</Reseller>
<Username>myuser</Username>
<Password>mypassword</Password>
</AuthenticationParameters>
<CommandParameters>
<DomainName>checkadomain.co</DomainName>
<LaunchPhase>GA</LaunchPhase>
</CommandParameters>
</CheckDomainAvailability>
</soap12:Body>
</soap12:Envelope>
I've contacted them but they do not offer a PHP API.
I would like to use the SoapClient class built in PHP.
The question is:
How do I send the request and print the answer?
Looks like your WSDL is located at https://live.domainbox.net/?WSDL.
Here's an example using the native PHP SoapClient.
$client = new SoapClient('https://live.domainbox.net/?WSDL');
// populate the inputs....
$params = array(
'AuthenticationParameters' => array(
'Reseller' => '',
'Username' => '',
'Password' => ''
),
'CommandParameters' => array(
'DomainName' => '',
'LaunchPhase' => ''
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);
To get this working I needed to change the first line to get the right version of soap to 1.2.
Also a previous comment
$client = new SoapClient('https://live.domainbox.net/?WSDL', array('soap_version' => SOAP_1_2));
// populate the inputs....
$params = array(
'AuthenticationParameters' => array(
'Reseller' => '',
'Username' => '',
'Password' => ''
),
'CommandParameters' => array(
'DomainName' => '',
'LaunchPhase' => ''
)
);
$result = $client->CheckDomainAvailability($params);
print_r($result);