定制 webreinvent/laravel-usps 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

  1. 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.
  2. Whether you want SSL verification enabled for API requests:

    • This setting is set to true by default for security reasons. You can override this behavior by setting the verrifyssl config setting to false. Do this at your own risk.
  3. 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 for env, it will default to the environment recognized by laravel. This setting takes precedence over APP_ENV from your .env file.

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 webreinvent/laravel-usps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-09