亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

php 計(jì)算UPS運(yùn)費(fèi) ( UPS shipping cost )

系統(tǒng) 2979 0

Pretty much every website that implements a shopping cart with online payment and checkout of products to be shipped, needs to have a shipping calculator. Depending on the company or companies that you choose to ship the products with, you'll need to read the documentation of their web service. One popular choice is UPS, and because the documentation on implementing their shipping calculator is scarce, that's the one we're going to code in this tutorial.

?



First you may want to sign up with UPS.com. It's not really needed for the implementation we're doing in this tutorial, however if you'll want to go more advanced, you'll need a developer key and an access key, and at the end of this tutorial there's more information on that.

?



Let's start with creating the form. In your real application you're probably going to fill your own package size and weight depending on the products ordered. But here we'll be entering these details through the form.

?


前提: 已開啟apache cURL 模塊

?

    <form action="UPSShip.php" method="post">
Address Type:
<select name="selResidential">
   <option value="01">Residential</option>
   <option value="02">Commercial</option>
</select>
<br />
Packaging:
<select name="selPackaging">
   <option value="00">Customer Packaging</option>
   <option value="01">UPS Letter Envelope</option>
   <option value="03">UPS Tube</option>
   <option value="21">UPS Express Box</option>
   <option value="24">UPS Worldwide 25KG Box</option>
   <option value="25">UPS Worldwide 10KG Box</option>
</select>
<br />
Service Type:
<select name="selService">
   <option value="1DM">Next Day Air Early AM</option>
   <option value="1DA">Next Day Air</option>
   <option value="1DP">Next Day Air Saver</option>
   <option value="2DM">2nd Day Air AM</option>
   <option value="2DA">2nd Day Air</option>
   <option value="3DS">3 Day Select</option>
   <option value="GND">Ground</option>
   <option value="STD">Canada Standard</option>
   <option value="XPR">Worldwide Express</option>
   <option value="XDM">Worldwide Express Plus</option>
   <option value="XPD">Worldwide Expedited</option>
   <option value="WXS">Worldwide Saver</option>
</select>
<br />
Rate:
<select name="selRate">
   <option value="Regular+Daily+Pickup">Daily Pickup service</option>
   <option value="OP_WEB">Oncall Air Pickup Web (arrange on the web for UPS to pick up my packages)</option>
   <option value="OP_PHONE">Oncall Air Pickup Phone (arrange by phone for UPS to pick up my packages)</option>
   <option value="One+Time+Pickup">One Time Pickup</option>
   <option value="Letter+Center">Drop-box Letter Center</option>
   <option value="Customer+Counter">Customer Counter</option>
</select>
<br />
Package Weight: <input type="text" name="txtPackWeight" value="1" /> pounds
<br />
Package Length: <input type="text" name="txtPackLength" value="5" /> inches
<br />
Package Width: <input type="text" name="txtPackWidth" value="5" /> inches
<br />
Package Height: <input type="text" name="txtPackHeight" value="5" /> inches
<br />
From Zip: <input type="text" name="txtFromZip" value="98052" />
<br />
From City: <input type="text" name="txtFromCity" value="Redmond" />
<br />
From Country: <input type="text" name="txtFromCountry" value="US" />
<br />
To Zip: <input type="text" name="txtToZip" value="94043" />
<br />
To City: <input type="text" name="txtToCity" value="Mountain View" />
<br />
To Country: <input type="text" name="txtToCountry" value="US" />
<br />
<input type="submit" value="Submit" />
</form>
  
?

?

As you can see, there are some specific codes that specify the service type, rate and package. You should check the UPS Online Tools Developer's Guide for a complete list on these.

Now that we got the HTML part ready, let's do the PHP. The following PHP code should be placed above the HTML form, in the same file (UPSShip.php.)

?

    <?php
if($_POST['txtFromZip'])
{
   $Url = join("&", array("http://www.ups.com/using/services/rave/qcostcgi.cgi?accept_UPS_license_agreement=yes",
   "10_action=3",
   "13_product=".$_POST['selService'],
   "14_origCountry=".$_POST['txtFromCountry'],
   "15_origPostal=".$_POST['txtFromZip'],
   "origCity=".$_POST['txtFromCity'],
   "19_destPostal=".$_POST['txtToZip'],
   "20_destCity=".$_POST['txtToCity'],
   "22_destCountry=".$_POST['txtToCountry'],
   "23_weight=".$_POST['txtPackWeight'],
   "47_rateChart=".$_POST['selRate'],
   "48_container=".$_POST['selPackaging'],
   "49_residential=".$_POST['selResidential'],
   "25_length=".$_POST['txtPackLength'],
   "26_width=".$_POST['txtPackWidth'],
   "27_height=".$_POST['txtPackHeight']));

   $Resp = fopen($Url, "r");
   while(!feof($Resp))
   {   
      $Result = fgets($Resp, 500);
      $Result = explode("%", $Result);
      $Err = substr($Result[0], -1);

      switch($Err)
      {
         case 3:
         $ResCode = $Result[8];
         break;
         case 4:
         $ResCode = $Result[8];
         break;
         case 5:
         $ResCode = $Result[1];
         break;
         case 6:
         $ResCode = $Result[1];
         break;
      }
   }
   fclose($Resp);
   if(!$ResCode)
   {
      $ResCode = "An error occured.";
   }
   echo $ResCode;
}
?>
  
?

?

All that we're doing is to pass the values of the form fields to an URL at ups.com. That page will then return the shipping cost, or a message such as "The requested service is invalid from the selected origin."



?

Getting a Developer's Key and an Access Key from UPS



There are more options provided by UPS not only in calculating the shipping cost, but also in buying and printing the shipping label. More information on those services is available at the UPS site; it's likely that you'll be needing a Developer's Key and an Access Key for that. To get one is as simple as 1, 2, 3... 4, 5, 6. Or is it?

?

?

?

It's actually not that easy to obtain the access key, you have to go through a number of forms.

First you need to register with My UPS: https://www.ups.com/one-to-one/register?sysid=myups&lang=en&langc=US&loc=en_US

?


Then you need to sign up for UPS OnLine Tools by entering more information about you and your company, including your account number (you got this in an email from UPS when you signed up.)
You know you're signed up with UPS OnLine Tools when you get this message "Thank you for joining the growing community of UPS OnLine? Tool end users. Upon your agreement to the developer's license, a Developer's Key has been issued and will be e-mailed shortly to the address you provided during registration. Please continue by selecting one of the UPS OnLine Tools listed below."

?


Then you get emailed a download key, followed by an access key. "An Access Key provides exactly that -- access to UPS systems, which hold the information you or your customers need to ship, track, or rate a package. Your Developer's Key lets you get UPS OnLine Tool documentation; the Access Key lets you actually implement UPS OnLine? Tools."

?


In order to get the access key, you need to go through one more form, which should be already filled with your current account information. Finally you should receive your Access Key in an email, and in the confirmation message:

?

?

Your HTML Access Key is XXXXXXXXXXXXXX.

You now have access to the following UPS OnLine? Tools:

UPS Rates & Service Selection HTML , Version 1.0
UPS Tracking HTML, Version 3.0

?

?

?


參考來源:

?

UPS

1. http://www.geekpedia.com/tutorial213_Creating-a-UPS-Shipping-Calculator.html

2. Calculating UPS Shipping Rate with PHP

3. http://www.marksanborn.net/php/new-ups-php-project-at-google-code/

4. http://www.marksanborn.net/php/tracking-ups-packages-with-php/

?

USPS

1. http://www.marksanborn.net/php/calculating-usps-shipping-rates-with-php/

2. http://www.marksanborn.net/php/printing-a-label-for-usps-with-php/

?

?

?

?

?

php 計(jì)算UPS運(yùn)費(fèi) ( UPS shipping cost )


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 嘿咻嘿咻免费区在线观看吃奶 | 亚洲天天做日日做天天欢毛片 | 国产在线一区视频 | 日韩精品另类天天更新影院 | 亚洲欧美国产另类视频 | 激情综合网色播五月 | 青青草狠狠干 | 日本中文字幕网站 | 欧美亚洲国产精品久久高清 | 91热久久免费频精品动漫99 | 久久精品亚洲99一区二区 | 国产伦理一区二区三区 | 美女一级毛片 | 久久99久久99精品免费看动漫 | 国产热久久精 | 精品在线播放视频 | 日韩亚洲欧美性感视频影片免费看 | 蜜月tv| 亚洲天天操 | 一区二区三区免费在线 | 九九热国产视频 | 欧美xxxxx九色视频免费观看 | 美女视频国产 | 激情影院a | 在线综合 亚洲 欧美中文字幕 | 久久综合久美利坚合众国 | 国产福利第一页 | 久久永久免费视频 | 亚洲精品大片 | 香蕉尹人 | 一级特黄高清完整大片 | 男人的天堂黄 | 一级毛片在线 | 久久色网 | 蜜桃视频黄色 | 久久精品视频8 | 日韩欧美一区二区在线观看 | 日本久久久久久久中文字幕 | 精品久久久一二三区 | 亚洲综合国产 | 99精品视频看国产啪视频 |