webreinvent/laravel-usps
Composer 安装命令:
composer require webreinvent/laravel-usps
包简介
USPS API wrapper for Laravel framework
README 文档
README
This package provides a very simple wrapper for the United States Postal Service API. Currently, this package only provides address validation features, but will soon comprise all features offered by the USPS API.
Prerequisites
Be sure to register at www.usps.com/webtools/ to receive your unique user ID from the United States Postal Service. This user ID is required to use this package.
Installation
composer require webreinvent/laravel-usps
Configuration
There are three important configurations.
-
Your USPS user ID:
- If you have not received your USPS user ID, follow the link in the prerequisites section to register with the United States Postal Service. It is required to use this package.
-
Whether you want SSL verification enabled for API requests:
- This setting is set to
trueby default for security reasons. You can override this behavior by setting theverrifysslconfig setting tofalse. Do this at your own risk.
- This setting is set to
-
Which environment you are working in:
- The options are
'local' and 'production'which tell the package which API url to use, testing or production respectively. If no configuration is found forenv, it will default to the environment recognized by laravel. This setting takes precedence overAPP_ENVfrom your.envfile.
- The options are
We recommend placing all configuration settings in your .env file and use Laravel's env() helper function to access these values.
In config/services.php add these three settings.
'usps' => [ 'userid' => env('USPS_USER_ID'), // string 'verifyssl' => env('USPS_VERIFY_SSL'), // bool 'env' => env('USPS_ENV') //string ];
Usage
The current features offered by this package are:
Address Validation
The Address class handles creating and formatting address data. Pass the constructor an associative array of address details. Array keys are case-sensitive.
Below is an example of creating an address and making an api request for validation.
use WebReinvent\Usps\Address; $address = new Address([ 'Address2' => '6406 Ivy Lane', 'City' => 'Greenbelt', 'State' => 'MD', 'Zip5' => 20770 ]); $response = $address->validate();
The USPS api supports up to 5 address validations per request. If you need to validate more than one address at a time, pass an array of addresses to the Address constructor.
use WebReinvent\Usps\Address; $address1 = [ 'Address2' => '6406 Ivy Lane', 'City' => 'Greenbelt', 'State' => 'MD', 'Zip5' => 20770 ]; $address2 = [ 'Address2' => '2185 Sandy Drive', 'City' => 'Franklin', 'State' => 'VA', 'Zip5' => 32050 ]; $addresses = new Address([$address1, $address2]); $response = $addresses->validate();
The response will contain the corrected address, or an error if not enough information was given or the address does not exists.
Response Formatting
You can specify the format of the response by passing an optional, case-insensitive parameter to the validate method. The default format is an associative array.
$address = new Address([/* address info */ ]); $json = $address->validate('json'); $object = $address->validate('object'); $string = $address->validate('string');
webreinvent/laravel-usps 适用场景与选型建议
webreinvent/laravel-usps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.28k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「usps」 「laravel usps」 「usps api」 「laravel 7」 「laravel 7 usps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webreinvent/laravel-usps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webreinvent/laravel-usps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webreinvent/laravel-usps 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple PHP class for United States Postal Service (USPS) addresses
PHP wrapper for USPS Web Tools API
The PHP SDK of TrackingMore API
A PSR-7 compatible library for making CRUD API endpoints
A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.
Symfony bundle for Geonames API
统计信息
- 总下载量: 4.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-09