德国邮政敦豪/sdk-api-unified-location-finder

德国邮政敦豪集团统一位置查找器API SDK

3.2.0 2024-05-24 10:36 UTC

This package is auto-updated.

Last update: 2024-08-27 15:40:17 UTC


README

DPDHL统一位置查找器API SDK包提供了以下Web服务的接口

  • 位置查找 - 统一

要求

系统要求

  • PHP 8.1+ 并带有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:静态分析工具
  • rector/rector:自动重构工具,帮助PHP升级
  • fig/log-testpsr/log的测试实用工具

安装

$ composer require dhl/sdk-api-unified-location-finder

卸载

$ composer remove dhl/sdk-api-unified-location-finder

测试

$ ./vendor/bin/phpunit -c test/phpunit.xml

功能

DPDHL统一位置查找器API SDK支持以下功能

  • 查找用于发送和接收包裹的DHL服务点。

公共API

库中适合消费的组件包括

  • 服务
    • 服务工厂
    • 位置查找服务
  • 数据传输对象
    • 带地址、地理坐标、营业时间规定的服务点位置

用法

$consumerKey = 'Your application consumer key';
$logger = new \Psr\Log\NullLogger();

$serviceFactory = new \Dhl\Sdk\UnifiedLocationFinder\Service\ServiceFactory();
$service = $serviceFactory->createLocationFinderService($consumerKey, $logger);

try {
    /** @var \Dhl\Sdk\UnifiedLocationFinder\Api\Data\LocationInterface $locations  */
    $locations = $service->getPickUpLocations(
        $countryCode = 'DE',
        $postalCode = '04129',
        $city = 'Leipzig',
        $street = 'Nonnenstraße 11d',
        $service = 'parcel-eu',
        $radius = 2000,
        $limit = 25
    );
} catch (\Dhl\Sdk\UnifiedLocationFinder\Exception\ServiceException $e) {
    // handle errors
}

错误处理

SDK只会抛出类型为\Dhl\Sdk\UnifiedLocationFinder\Exception\ServiceException的异常。可以使用ServiceException的子类来描述发生的错误类型。

\Dhl\Sdk\UnifiedLocationFinder\Exception\DetailedServiceException表示异常包含适合显示给最终用户的可读错误消息。