tejrajs / usps-api
美国邮政服务 api
0.0.1
2015-08-07 07:08 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-14 16:13:43 UTC
README
此包装器允许您对USPS api执行一些基本调用。当前支持的一些功能包括
- 运费计算器(国内外都支持)
- 通过地址查找邮政编码
- 通过邮政编码查找城市/州
- 验证地址
- 创建优先快递标签
- 创建开放和分发快递标签
- 创建国际快递标签(快递、优先、平邮)
- 服务配送计算器
- 确认跟踪
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist tejrajs/usps-api "*"
或
"tejrajs/usps-api": "*"
将其添加到您的 composer.json
文件的require部分。
用法
一旦安装了此扩展,只需在您的代码中使用它即可
USPS 地址验证
<?php use tejrajs\uspsapi\USPSAddressVerify; use tejrajs\uspsapi\USPSAddress; $verify = new USPSAddressVerify('xxxx'); // During test mode this seems not to always work as expected //$verify->setTestMode(true); // Create new address object and assign the properties // apartently the order you assign them is important so make sure // to set them as the example below $address = new USPSAddress; $address->setFirmName('Apartment'); $address->setApt('100'); $address->setAddress('9200 Milliken Ave'); $address->setCity('Rancho Cucomonga'); $address->setState('CA'); $address->setZip5(91730); $address->setZip4(''); // Add the address object to the address verify class $verify->addAddress($address); // Perform the request and return result print_r($verify->verify()); print_r($verify->getArrayResponse()); var_dump($verify->isError()); // See if it was successful if($verify->isSuccess()) { echo 'Done'; } else { echo 'Error: ' . $verify->getErrorMessage(); } ?>```