php - 获取所有 TNT 运输方式的 TNT Australia 实时运费

标签 php xml api curl

我想获取 TNT Australia 的始发地和送货地址之间所有运输方式的实时费率。

例如公路快车、隔夜特快、隔夜 PAYU 挎包、9:00 特快、10:00 特快等

我正在使用下面的代码。

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;

但给我一条消息,比如登录详细信息无效。

我们的 TNT 帐户创建于 http://www.tntexpress.com.au/链接。

我使用 php 作为服务器端语言。

最佳答案

经过与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 实时运费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31391469/

相关文章:

android - 尝试运行 PhoneGap APP 时 AndroidManifest 出现问题

java - 使用 XSLT 从 xml 文件的父标签和子标签获取值

python - 当多个字段具有相同名称时如何插入xml python?

php - 从 mysql 更新到 mysqli newbie

php - 如何根据一天(而不是日期)过滤集合?

php - 使用 PHP 自动检测并在 html 内容中嵌入 MP4/MP3 链接

api - 谷歌博客搜索 API 的替代 API

php - 外部启动 PHP 脚本的 MYSQL 触发器

api - 有没有一种方法可以检查 Foursquare field 速率限制,而无需实际支付请求费用?

c++ - 我应该在公共(public)接口(interface)的结构中将相关参数分组吗?