Hi
I'm trying to write a TNT express module for Australia but really don't know enough about PHP or POSTing.'
The TNT documentation supplies the following but when I try to formulate like the auspost or fastway modules
curl_setopt($ch,CURLOPT_UR:,'https://tntexpress.com.au/rtt/inputRequest.asp?username=user&password=pass&version=2&xmlRequest=...')
I get a simple
XML Invalid: XML document must have a top level element.
Can someone please point me in the right direction?
Thanks in Advance.
Peter
TNTExpress Example
---
POST /rtt/inputRequest.asp HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 1767
Host: www.tntexpress.com.au
username=user&password=pass&version=2&xmlRequest=%3C%3Fxml+version%3D%221.0%22%3F%3E%0D%0A%3Cenquiry+xmlns%3D%22http%3A%2F%2Fwww.tntexpress.com.au%22%3E%0D%0A++%3CratedTransitTimeEnquiry%3E%0D%0A++++%3CcutOffTimeEnquiry%3E%0D%0A++++++%3CcollectionAddress%3E%0D%0A++++++++%3Csuburb%3ESydney%3C%2Fsuburb%3E%0D%0A++++++++%3CpostCode%3E2000%3C%2FpostCode%3E%0D%0A++++++++%3Cstate%3ENSW%3C%2Fstate%3E%0D%0A++++++%3C%2FcollectionAddress%3E%0D%0A++++++%3CdeliveryAddress%3E%0D%0A++++++++%3Csuburb%3EMelbourne%3C%2Fsuburb%3E%0D%0A++++++++%3CpostCode%3E3000%3C%2FpostCode%3E%0D%0A++++++++%3Cstate%3EVIC%3C%2Fstate%3E%0D%0A++++++%3C%2FdeliveryAddress%3E%0D%0A++++++%3CshippingDate%3E2007-11-05%3C%2FshippingDate%3E%0D%0A++++++%3CuserCurrentLocalDateTime%3E%0D%0A++++++++2007-11-05T10%3A00%3A00%0D%0A++++++%3C%2FuserCurrentLocalDateTime%3E%0D%0A++++++%3CdangerousGoods%3E%0D%0A++++++++%3Cdangerous%3Efalse%3C%2Fdangerous%3E%0D%0A++++++%3C%2FdangerousGoods%3E%0D%0A++++++%3CpackageLines+packageType%3D%22D%22%3E%0D%0A++++++++%3CpackageLine%3E%0D%0A++++++++++%3CnumberOfPackages%3E1%3C%2FnumberOfPackages%3E%0D%0A++++++++++%3Cdimensions+unit%3D%22cm%22%3E%0D%0A++++++++++++%3Clength%3E20%3C%2Flength%3E%0D%0A++++++++++++%3Cwidth%3E20%3C%2Fwidth%3E%0D%0A++++++++++++%3Cheight%3E20%3C%2Fheight%3E%0D%0A++++++++++%3C%2Fdimensions%3E%0D%0A++++++++++%3Cweight+unit%3D%22kg%22%3E%0D%0A++++++++++++%3Cweight%3E1%3C%2Fweight%3E%0D%0A++++++++++%3C%2Fweight%3E%0D%0A++++++++%3C%2FpackageLine%3E%0D%0A++++++%3C%2FpackageLines%3E%0D%0A++++%3C%2FcutOffTimeEnquiry%3E%0D%0A++++%3CtermsOfPayment%3E%0D%0A++++++%3CsenderAccount%3E20003583%3C%2FsenderAccount%3E%0D%0A++++++%3Cpayer%3ES%3C%2Fpayer%3E%0D%0A++++%3C%2FtermsOfPayment%3E%0D%0A++%3C%2FratedTransitTimeEnquiry%3E%0D%0A%3C%2Fenquiry%3E%0D%0A
---
See i this helps you.... TNT is very fussy and not at all helpful in building interfaces to their API.
Code: Select all
private function getTNTExpressxml($shipDate, $address, $length=1, $width=1, $height=1, $weight=1)
{
$request_xml = "<?xml version='1.0'?><enquiry xmlns='http://www.tntexpress.com.au'><ratedTransitTimeEnquiry><cutOffTimeEnquiry>";
$request_xml .= "<collectionAddress><suburb>" . $this->config->get('tntexpress_suburb') . "</suburb><postCode>" . $this->config->get('tntexpress_postcode') . "</postCode><state>" . $this->config->get('tntexpress_state') . "</state></collectionAddress>";
$request_xml .= "<deliveryAddress><suburb>" . $address['city'] . "</suburb><postCode>" . $address['postcode'] . "</postCode><state>" . $address['zone'] . "</state></deliveryAddress>";
$request_xml .= "<shippingDate>" .$shipDate . "</shippingDate>";
$request_xml .= "<userCurrentLocalDateTime>" .date(DATE_ATOM) ."</userCurrentLocalDateTime>";
$request_xml .= "<dangerousGoods><dangerous>false</dangerous></dangerousGoods><packageLines packageType='N'><packageLine>";
$request_xml .= "<numberOfPackages>1</numberOfPackages>";
$request_xml .= "<dimensions unit='cm'><length>" . $length ."</length><width>" . $width ."</width><height>" . $length ."</height></dimensions>";
$request_xml .= "<weight unit='kg'><weight>" . $weight ."</weight></weight></packageLine></packageLines></cutOffTimeEnquiry><termsOfPayment>";
$request_xml .= "<senderAccount>" . $this->config->get('tntexpress_account_id') ."</senderAccount><payer>S</payer></termsOfPayment></ratedTransitTimeEnquiry></enquiry>";
$data = array ('xmlRequest' => $request_xml, 'username' => $this->config->get('tntexpress_account_username'), 'password' => $this->config->get('tntexpress_account_password'));
$data = http_build_query($data);
$data = str_replace('&','&',$data);
$data = str_replace('+','%20',$data) ;
$data = str_replace('%2F','/',$data) ;
echo '<!--'.$request_xml.'-->';
$TNTURL = "https://www.tntexpress.com.au/Rtt/inputRequest.asp";
$ch = curl_init($TNTURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
}
Who is online
Users browsing this forum: No registered users and 2 guests