abantecart/ups-php
Composer 安装命令:
composer require abantecart/ups-php
包简介
UPS PHP SDK based on OAuth
README 文档
README
The UPS PHP SDK provides convenient access to the UPS RESTful API from applications written in the PHP language. It includes a batch of sets of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the UPS API. This SDK based on official UPS API Documentation Repository and generated with Swagger-Codegen Tool
Requirements
PHP 7.4 and later.
Composer
You can install the bindings via Composer. To install all supported APIs run the following command:
composer require abantecart/ups-php
If you prefer to install not all APIs you should to run this command inside selected API directory.
To use the bindings, use Composer's autoload:
require_once 'vendor/autoload.php';
Dependencies
The bindings require the following extensions in order to work properly:
If you use Composer, these dependencies should be handled automatically.
Getting Started
Generate Access Token:
//YOUR ACCOUNT NUMBER (6 characters) $accNumber = '******'; //UPS API Credentials (obtain after APP creation) $clientId = '***YOUR_UPS_API_CLIENT_ID***'; $password = '***YOUR_UPS_API_PASSWORD***'; $config = \UPS\OAuthClientCredentials\Configuration::getDefaultConfiguration() ->setUsername($clientId) ->setPassword($password) ->setHost('https://wwwcie.ups.com'); $apiInstance = new \UPS\OAuthClientCredentials\Request\OAuthClientCredentialsApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new \GuzzleHttp\Client(), $config ); $grant_type = "client_credentials"; // string | $x_merchant_id = $accNumber; // string | Client merchant ID try { $result = $apiInstance->createToken($grant_type, $x_merchant_id); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->generateToken: ', $e->getMessage(), PHP_EOL; }
Rating request:
// Configure OAuth2 access token for authorization: oauth2 $config = UPS\Rating\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN'); $apiInstance = new UPS\Rating\Request\RatingApi( // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. // This is optional, `GuzzleHttp\Client` will be used as default. new GuzzleHttp\Client(), $config ); $body = new \UPS\Rating\Rating\RATERequestWrapper(); // \UPS\Rating\Rating\RATERequestWrapper | Generate sample code for popular API requests by selecting an example below. To view a full sample request and response, first click "Authorize" and enter your application credentials, then populate the required parameters above and click "Try it out". $version = "v1"; // string | Indicates Rate API to display the new release features in Rate API response based on Rate release. See the New section for the latest Rate release. Supported values: v1, v1601, v1607, v1701, v1707, v2108, v2205. Length 5 $requestoption = "Shop"; // string | Valid Values: Rate = The server rates (The default Request option is Rate if a Request Option is not provided). Shop = The server validates the shipment, and returns rates for all UPS products from the ShipFrom to the ShipTo addresses. Rate is the only valid request option for Ground Freight Pricing requests. . Length 10 $trans_id = "trans_id_example"; // string | An identifier unique to the request. Length 32 $transaction_src = "testing"; // string | An identifier of the client/source application that is making the request.Length 512 $additionalinfo = ""; // string | Valid Values: timeintransit = The server rates with transit time information combined with requestoption in URL.Rate is the only valid request option for Ground Freight Pricing requests. Length 15 try { $result = $apiInstance->rate($body, $version, $requestoption, $trans_id, $transaction_src, $additionalinfo); print_r($result); } catch (Exception $e) { echo 'Exception when calling DefaultApi->rate: ', $e->getMessage(), PHP_EOL; }
More examples see in the _examples directory. Shipment creation and getting labels code available inside AbanteCart "UPS" extension since v1.4.3
Documentation
See the UPS API docs.
abantecart/ups-php 适用场景与选型建议
abantecart/ups-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.71k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2023 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「rest」 「api」 「oauth」 「web service」 「sdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 abantecart/ups-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abantecart/ups-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 abantecart/ups-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
BlockCypher's PHP SDK for REST API
Helper classes for creating cookie headers
统计信息
- 总下载量: 17.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-11