gls-m2-extension / sdk-api-parcel-processing
GLS 物流处理 Web API SDK
1.1.2
2024-08-08 15:01 UTC
Requires
- php: ^7.2.0 || ^8.0.0 || ^8.1.0 || ^8.2.0 || ^8.3.0
- ext-json: *
- netresearch/jsonmapper: ^4.0.0
- php-http/discovery: ^1.10.0
- php-http/httplug: ^2.2.0
- php-http/logger-plugin: ^1.2.1
- psr/http-client: ^1.0.1
- psr/http-client-implementation: ^1.0.0
- psr/http-factory: ^1.0.0
- psr/http-factory-implementation: ^1.0.0
- psr/http-message: ^1.0.0 || ^2.0.0
- psr/http-message-implementation: ^1.0.0
- psr/log: ^1.1.0 || ^2.0.0 || ^3.0.0
Requires (Dev)
- nyholm/psr7: ^1.0.0
- php-http/mock-client: ^1.5.0
- phpstan/phpstan: ^1.5.0
- phpunit/phpunit: ^8.0.0 || ^9.0.0
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-08 15:10:15 UTC
README
GLS 物流处理 API SDK 包提供了以下网络服务的接口
- GLS 物流处理 Web API
- GLS 物流取消 Web API
要求
系统要求
- PHP 7.2+ 并带有 JSON 扩展
包要求
netresearch/jsonmapper: 将 JSON 响应消息反序列化为 PHP 对象的映射器php-http/discovery: HTTP 客户端和消息工厂实现的发现服务php-http/httplug: 可插拔的 HTTP 客户端抽象php-http/logger-plugin: HTTPlug 的 HTTP 客户端记录插件psr/http-client: PSR-18 HTTP 客户端接口psr/http-factory: PSR-7 HTTP 消息工厂接口psr/http-message: PSR-7 HTTP 消息接口psr/log: PSR-3 记录接口
虚拟包要求
psr/http-client-implementation: 提供兼容 PSR-18 的 HTTP 客户端的任何包psr/http-factory-implementation: 提供兼容 PSR-7 的 HTTP 消息工厂的任何包psr/http-message-implementation: 提供兼容 PSR-7 的 HTTP 消息的任何包
开发包要求
nyholm/psr7: PSR-7 HTTP 消息工厂与消息实现phpunit/phpunit: 测试框架php-http/mock-client: HTTPlug 模拟客户端实现phpstan/phpstan: 静态分析工具squizlabs/php_codesniffer: 静态分析工具
安装
$ composer require glsgroup/sdk-api-parcel-processing
卸载
$ composer remove glsgroup/sdk-api-parcel-processing
测试
$ ./vendor/bin/phpunit -c test/phpunit.xml
特性
GLS 物流处理 API SDK 支持以下特性
- 创建带有标签的运输
- 取消包裹
创建运输
创建一个或多个包裹的运输并检索运输标签。可以按包裹订购增值服务。可以单独请求退货标签("仅退货")或与常规的"到"标签一起请求。
公共 API
适合消费的库组件包括
- 服务
- 服务工厂
- 运输服务
- 数据传输对象构建器
- 数据传输对象
- 带有包裹的运输
- 异常
用法
$logger = new \Psr\Log\NullLogger(); $serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory(); $service = $serviceFactory->createShipmentService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true); // REGULAR SHIPMENT $requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ShipmentRequestBuilder(); $requestBuilder->setShipperAccount($shipperId = '98765 43210'); $requestBuilder->setRecipientAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS-Germany-Straße 1 - 7', $name = 'Jane Doe' ); $requestBuilder->addParcel($parcelWeightA = 0.95); $requestBuilder->addParcel($parcelWeightB = 1.2); $request = $requestBuilder->create(); $shipment = $service->createShipment($request); // work with the web service response, e.g. persist label foreach ($shipment->getLabels() as $i => $label) { file_put_contents("/tmp/{$shipment->getConsignmentId()}-{$i}.pdf", $label); } // RETURN SHIPMENT $requestBuilder = new \GlsGroup\Sdk\ParcelProcessing\RequestBuilder\ReturnShipmentRequestBuilder(); $requestBuilder->setShipperAccount($shipperId = '98765 43210'); $requestBuilder->setShipperAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS-Germany-Straße 1 - 7', $name = 'Jane Doe' ); $requestBuilder->setRecipientAddress( $country = 'DE', $postalCode = '36286', $city = 'Neuenstein', $street = 'GLS Germany-Straße 1 - 7', $company = 'GLS Germany' ); $requestBuilder->addParcel($weight = 0.95, $qrCode = true); $request = $requestBuilder->create(); $shipment = $service->createShipment($request);
取消包裹
取消一个或多个包裹。
公共 API
适合消费的库组件包括
- 服务
- 服务工厂
- 取消服务
- 异常
用法
$logger = new \Psr\Log\NullLogger(); $serviceFactory = new \GlsGroup\Sdk\ParcelProcessing\Service\ServiceFactory(); $service = $serviceFactory->createCancellationService('basicAuthUser', 'basicAuthPass', $logger, $sandbox = true); $cancelledIds = $service->cancelParcels([$parcelIdA = '12345', $parcelIdB = '54321']);