php : 获取所有 tnt 运输方式的 TNT Australia 实时运费 [英] php : get TNT Australia live shipping rates of all tnt shipping methods
本文介绍了php : 获取所有 tnt 运输方式的 TNT Australia 实时运费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得 TNT Australia 在原产地和送货地址之间的所有运输方式的实时费率.
I want to get live rates of all shipping methods of TNT Australia between origin and delivery address.
比如Road Express、Overnight Express、Overnight PAYU Satchel、9:00 Express、10:00 Express等
我正在使用以下代码.
function sendToTNTServer( $Xml ) {
$postdata = http_build_query(
array(
//For Future reference
//the xml_in= ( the = ) is appended
//Automatically by PHP
'xml_in' => $Xml
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create( $opts );
$output = file_get_contents(
'http://www.tntexpress.com.au/expressconnect/pricing/getprice',
false,
$context
);
return $output;
}
$XmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<PRICEREQUEST>
<LOGIN>
<COMPANY>username</COMPANY>
<PASSWORD>password</PASSWORD>
<APPID>PC</APPID>
</LOGIN>
<PRICECHECK>
<RATEID>rate1</RATEID>
<ORIGINCOUNTRY>AU</ORIGINCOUNTRY>
<ORIGINTOWNNAME>Atherstone</ORIGINTOWNNAME>
<ORIGINPOSTCODE>2217</ORIGINPOSTCODE>
<ORIGINTOWNGROUP/>
<DESTCOUNTRY>AU</DESTCOUNTRY>
<DESTTOWNNAME>Alicante</DESTTOWNNAME>
<DESTPOSTCODE>6009</DESTPOSTCODE>
<DESTTOWNGROUP/>
<CONTYPE>N</CONTYPE>
<CURRENCY>AUD</CURRENCY>
<WEIGHT>18</WEIGHT>
<VOLUME>1</VOLUME>
<ACCOUNT/>
<ITEMS>1</ITEMS>
</PRICECHECK>
</PRICEREQUEST>";
$returnXml = sendToTNTServer( $XmlString );
echo $returnXml;
但是给我提示登录信息无效.
我们在 http://www.tntexpress.com.au/ 链接上创建的 TNT 帐户.
Our TNT account created on http://www.tntexpress.com.au/ link.
我使用 php 作为服务器端语言.
I am using php as server side language.
推荐答案
经过与 TNT 的大量讨论和讨论,我得到了答案.
I got the answer after lot of stuck and discussion with TNT.
<?php
/**
* Submit XML to the TNT
* server via a Stream instead
* of cURL.
*
* @Returns String (XML)
**/
function sendToTNTServer( $Xml ) {
$username = username starting with CIT000
$password = ******
$senderAccount = *******
$postdata = http_build_query(
array(
'Username' => $username,
'Password' => $password,
'XMLRequest' => $Xml
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create( $opts );
$output = file_get_contents(
'https://www.tntexpress.com.au/Rtt/inputRequest.asp',
false,
$context
);
return $output;
}
$XmlString = "<?xml version='1.0'?>
<enquiry xmlns='http://www.tntexpress.com.au'>
<ratedTransitTimeEnquiry>
<cutOffTimeEnquiry>
<collectionAddress>
<suburb>Sydney</suburb>
<postCode>2000</postCode>
<state>NSW</state>
</collectionAddress>
<deliveryAddress>
<suburb>Melbourne</suburb>
<postCode>3000</postCode>
<state>VIC</state>
</deliveryAddress>
<shippingDate>2007-11-05</shippingDate>
<userCurrentLocalDateTime>
2007-11-05T10:00:00
</userCurrentLocalDateTime>
<dangerousGoods>
<dangerous>false</dangerous>
</dangerousGoods>
<packageLines packageType='D'>
<packageLine>
<numberOfPackages>1</numberOfPackages>
<dimensions unit='cm'>
<length>20</length>
<width>20</width>
<height>20</height>
</dimensions>
<weight unit='kg'>
<weight>1</weight>
</weight>
</packageLine>
</packageLines>
</cutOffTimeEnquiry>
<termsOfPayment>
<senderAccount>$senderAccount</senderAccount>
<payer>S</payer>
</termsOfPayment>
</ratedTransitTimeEnquiry>
</enquiry>";
$returnXml = sendToTNTServer( $XmlString );
echo $returnXml;
?>
这篇关于php : 获取所有 tnt 运输方式的 TNT Australia 实时运费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文