(Close) PHP with SOAP, server to get xml from request
one text
I'am new hand about soap
I've a client.php code witch send a xml to server.php.
How to read xml to array in my server.php?
I always get the value without the key
Do I using wsdl to parse xml?
But I'm not good at wsdl...
Can someone help me? Thx a lot.
client.php
<?php
$data = '<?xml version = "1.0" encoding = "UTF-8"?>
<inputMessage>
<ns0:BankCollStatusAdviseRq xmlns:ns0 = "http://ns.tcb.com.tw/XSD/TCB/BC/Message/BankCollStatusAdviseRq/01">
<ns0:SeqNo>00000000</ns0:SeqNo>
<ns0:TxnCode>ARROWAPAN095912 </ns0:TxnCode>
<ns0:CollInfo>
<ns0:CollId>006</ns0:CollId>
<ns0:CurAmt>
<ns0:Amt>1000</ns0:Amt>
</ns0:CurAmt>
</ns0:CollInfo>
<ns0:SettlementInfo>
<ns0:SettlementId>0063201924</ns0:SettlementId>
</ns0:SettlementInfo>
</ns0:BankCollStatusAdviseRq>
<headers>
<Header.PartyInfo>
<ns0:PartyInfo xmlns:ns0 = "http://www.tibco.com/namespaces/bc/2002/04/partyinfo.xsd">
<from>
<name>BANK006</name>
</from>
<operationID>BankColl/1.0/BankCollStatusAdvise</operationID>
</ns0:PartyInfo>
</Header.PartyInfo>
</headers>
<ns0:_configData xmlns:ns0 = "http://tibco.com/namespaces/tnt/plugins/soap">
<endpointURL>https://dev.admin.roombook.com.tw/automsgclient_tc.php?wsdl</endpointURL>
<soapAction>/BankColl</soapAction>
</ns0:_configData>
</inputMessage>';
$url = "http://localhost:8080/test/soap/demo2/server.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/soap+xml",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
server.php
<?php
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
exit;
}
$postData = trim(file_get_contents('php://input'));
echo "<pre>";print_r($postData);echo "</pre>";
libxml_use_internal_errors(true);
$xml = simplexml_load_string($postData);
if($xml === false) {
header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Request", true, 400);
foreach(libxml_get_errors() as $xmlError) {
echo $xmlError->message . "\n";
}
exit;
}
?>
Source