- 浏览: 13747968 次
- 性别:
- 来自: 洛杉矶
文章分类
- 全部博客 (1994)
- Php / Pear / Mysql / Node.js (378)
- Javascript /Jquery / Bootstrap / Web (435)
- Phone / IOS / Objective-C / Swift (137)
- Ubuntu / Mac / Github / Aptana / Nginx / Shell / Linux (335)
- Perl / Koha / Ruby / Markdown (8)
- Java / Jsp (12)
- Python 2 / Wxpython (25)
- Codeigniter / CakePHP (32)
- Div / Css / XML / HTML5 (179)
- WP / Joomla! / Magento / Shopify / Drupal / Moodle / Zimbra (275)
- Apache / VPN / Software (31)
- AS3.0/2.0 / Flex / Flash (45)
- Smarty (6)
- SEO (24)
- Google / Facebook / Pinterest / SNS (80)
- Tools (22)
最新评论
-
1455975567:
xuezhongyu01 写道wocan23 写道我想问下那个 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
xuezhongyu01:
wocan23 写道我想问下那个111.1是怎么得来的我也看不 ...
Mysql: LBS实现查找附近的人 (两经纬度之间的距离) -
18335864773:
试试 pageoffice 在线打开 PDF 文件吧. pag ...
jquery在线预览PDF文件,打开PDF文件 -
青春依旧:
opacity: 0.5; 个人喜欢这种方式!关于其他css特 ...
css透明度的设置 (兼容所有浏览器) -
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
搞定网页打印自动分页问题
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: 在类(class)中加载动态函数, 变量函数或半变量函数 variable function/method
2016-09-03 07:54 7185最终实例在下方 以前 ... -
MySQL入门 (七) : 储存引擎与资料型态
2016-09-03 07:49 45651 表格与储存引擎 表格(table)是资料库中用来储存 ... -
MySQL入门 (六) : 字元集与资料库
2016-09-03 07:47 45781 Character Set与Collation 任何 ... -
MySQL入门 (五) : CRUD 与资料维护
2016-09-03 07:46 54881 取得表格资讯 1.1 DESCRIBE指令 「 ... -
MySQL入门 (四) : JOIN 与UNION 查询
2016-09-03 07:42 45121 使用多个表格 在「world」资料库的「countr ... -
PHP: 关键字global 和 超全局变量$GLOBALS的用法、解释、区别
2016-08-31 12:07 5046$GLOBALS 是一个关联数组,每一个变量为一个 ... -
MySQL入门 (三) : 运算式与函式
2016-08-31 12:01 4392运算式(expressions)已经 ... -
MySQL入门 (二) : SELECT 基础查询
2016-08-31 11:56 46911 查询资料前的基本概念 1.1 表格、纪录 ... -
MySQL入门 (一) : 资料库概论与MySQL的安装
2016-08-31 11:51 44691. 储存与管理资料 储存与管理资料一直是资讯应用上最基本 ... -
MySQL入门 (九) : 子查询 Subquery
2016-08-30 02:26 44551 一个叙述中的查询叙述 子查询(subquery)是一 ... -
PHP: 用readonly取代disabled来获取input值 submit a disabled input in a form could not ge
2016-08-30 02:21 2718The form is like below; <f ... -
PHP7革新与性能优化
2016-08-30 02:20 2155有幸参与2015年的PHP技 ... -
Mysql: 图解 inner join、left join、right join、full outer join、union、union all的区别
2016-08-18 06:03 3131对于SQL的Join,在学习起来可能是比较乱的。我们知道, ... -
Comet 反Ajax: 基于jQuery与PHP实现Ajax长轮询(LongPoll)
2016-08-18 06:00 1386传统的AJAX轮询方式,客服端以用户定义的时间间隔去服务器上 ... -
PHP:ServerPush (Comet推送) 技术的探讨
2016-08-18 05:58 1048PHP中Push(推送)技术的探讨 [http://vi ... -
PHP: 手把手编写自己的 MVC 框架实例教程
2016-08-16 05:33 18221 什么是MVC MVC模式(Model-View-Con ... -
PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)
2016-07-29 12:55 1774原文: PHP5: mysqli 插入, 查询, 更新 ... -
MongoDB 教程索引 (附有视频)
2016-07-27 10:54 757MongoDB 教程索引 MongoDB 教程一: ... -
Node.js 模块之Nimble流程控制
2016-07-18 12:59 1088NodeJS异步的特性有时候 ... -
Node.js web应用模块之Supervisor
2016-07-18 12:56 2335在开发或调试Node.js应 ...
相关推荐
【标题】"可以计算UPS的计算器"所涉及的知识点主要集中在电力系统和计算机编程领域,尤其是与不间断电源(Uninterruptible Power Supply, UPS)相关的计算和VB(Visual Basic)编程技术。 UPS是一种电力设备,其...
3. **运费计算**:核心功能是计算运费,这涉及输入如包装重量、尺寸、目的地、服务类型(比如标准快递、次日达等)等信息,然后从UPS服务器获取相应费用。 4. **错误处理**:与任何API通信一样,源代码会包含错误...
UPS蓄电池延时自动计算表,按恒功率计算,办入UPS功率、电池总电压、单电池电压、单电池容量即可,适合投标及方案配置计算
UPS供电时长计算 UPS(Uninterruptible Power Supply, 不间断电源)是指一种可以在电源中断或电压不稳时,继续为负载供电的电源设备。UPS供电时长计算是指计算UPS可以为负载供电的时间长度。 在进行UPS供电时长...
计算机UPS供电CAD图纸
UPS蓄电池配置及蓄电池放电时间的计算对于确保不间断电源系统(UPS)的稳定运行至关重要。UPS系统能够保证在电源故障或电力中断时,关键的电子设备依然能够得到持续的电力供应,从而确保业务流程的连续性。为了达到...
本文将深入解析UPS容量计算的重要知识点,通过实例说明如何正确计算UPS的容量及电池配置,确保重要设备在电网异常或停电情况下的正常运行。 ### UPS容量计算的重要性 UPS的主要功能是在市电中断或不稳定时提供纯净...
"在线UPS配备电池的计算方法" 在线UPS配备电池的计算方法是指选择电池数量和容量的方法,以满足UPS的电池需求。该计算方法是基于电池的技术说明书,确定电池电压(额定电压),然后计算所需的电池容量(安时数)。 ...
了解UPS电池的计算方法对于选购和配置UPS系统至关重要。 首先,我们需要理解UPS电池计算中的关键参数。UPS功率,通常以VA(伏特安培)表示,是UPS的额定输出功率,代表了UPS在满负荷下能提供的最大电力。时间则指在...
本文将详细解析如何计算和配置UPS的容量。 首先,选择适合的UPS类型至关重要。对于个人办公和家庭用户,后备式UPS如山特的型号,因其经济实惠和小巧便携而成为理想选择。它们可以为个人电脑提供短期电力保障。而...
### UPS放电时间计算方法详解 #### 一、引言 不间断电源系统(Uninterruptible Power Supply,简称UPS)作为电力保障的重要组成部分,在数据中心、服务器机房等关键领域发挥着不可替代的作用。为了确保UPS系统在...
### UPS蓄电池后备时间计算方法详解 #### 一、引言 UPS(不间断电源)系统作为保障电力供应稳定的关键设备,在数据中心、服务器机房等场景中扮演着至关重要的角色。为了确保在市电中断时能够持续供电,正确计算UPS...
UPS容量及电池计算公示,根据实际的时间需要计算出准确的容量
其中,UPS的蓄电池后备时间计算是评估UPS性能和确定所需电池容量的关键步骤。本文将详细介绍两种常用的UPS蓄电池后备时间计算方法:恒功率法和最大放电电流法。 ### 恒功率法 恒功率法是一种基于负载功率和逆变器...
UPS 电池放电计算 UPS 电池放电计算是指根据 UPS 的配置和负载情况,计算蓄电池的容量和放电功率,以确保 UPS 的稳定运行和长时间backup电池的可靠性。本文将详细介绍 UPS 电池放电计算的方法和公式,并结合施耐德 ...
UPS电池计算的方法及公式全在里面,包括实际的电池算法及损耗计算
### UPS电池选型计算方法详解 #### 一、引言 不间断电源(Uninterruptible Power Supply,简称UPS)是现代数据中心、服务器房等关键设施中不可或缺的重要设备之一,用于在电网发生异常时保障电力供应的连续性。...
如果是分布式供电,根据每台UPS的负载分别计算。对于电阻性负载,功率因数为1,而电感性和容性负载的功率因数通常较低,需要将W值转换为VA值进行计算。 其次,负载类型也会影响UPS的容量。计算机类负载对UPS的功率...