定制 blobswop/dpd-php-api 二次开发

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

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

blobswop/dpd-php-api

Composer 安装命令:

composer require blobswop/dpd-php-api

包简介

PHP wrapper for DPD Germany SOAP API

README 文档

README

About

PHP wrapper for DPD Germany SOAP API.

Using:

  • LoginService version 2.0
  • ParcelLifeCycleService version 2.0
  • ShipmentService version 4.4

Requirements

This library uses PHP 8.0+

Installation

It is recommended that you install the PHP UPS API library through composer. To do so, run the Composer command to install the latest stable version of PHP DPD API:

$ composer require blobswop/dpd-php-api

Table Of Content

  1. Authorization
  2. Create order (get tracking number and generate label)
  3. Track parcel

Authorization

// set development environment
\Dpd\Api::dev();
$response = null;

try {
    $response = \Dpd\Api::me()->auth(
        new \Dpd\Business\Credentials('sandboxdpd', 'password', 'en_US')
    );
    
    if ($response instanceof \Dpd\Business\AuthenticationFault) {
        // authentication fault
        print_r($response);     
    } elseif ($response instanceof \Dpd\Business\Login) {
        // authentication success - save token
        print_r($response);
    }
} catch(\Throwable $e) {
    print_r($e);
}

Example response for authentication fault:

Dpd\Business\AuthenticationFault Object
(
    [errorCode:protected] => LOGIN_8
    [errorMessage:protected] => The combination of user and password is invalid.
)

Example response for success authentication:

Dpd\Business\Login Object
(
    [delisId:protected] => sandboxdpd
    [customerUid:protected] => sandboxdpd
    [authToken:protected] => LT***RR
    [depot:protected] => 0998
)

Create order

// set development environment
\Dpd\Api::dev();
$response = null;

try {
    $authentication =
        (new \Dpd\Business\Authentication)
            ->setDelisId('sandboxdpd')
            ->setAuthToken('L***R')
            ->setMessageLanguage('en_US');

    $storeOrders =
        (new \Dpd\Business\StoreOrders())
            ->setPrintOptions(
                (new \Dpd\Business\PrintOptions())
                    ->addPrintOption(
                        (new \Dpd\Business\PrintOption())
                            ->setPaperFormatA4()
                            ->setOutputFormat(\Dpd\Business\OutputFormatType::multipageImage())
                    )
                    ->setSplitByParcel(true)
            )
            ->addOrder(
                (new \Dpd\Business\ShipmentServiceData())
                    ->setGeneralShipmentData(
                        (new \Dpd\Business\GeneralShipmentData())
                            ->setProductDpdClassic()
                            ->setSendingDepot('0141')
                            ->setMpsWeight(500)
                            ->setMpsVolume(100 * 10 * 50)
                            ->setSender(
                                (new \Dpd\Business\AddressWithType())
                                    ->setAddressTypeCommercial()
                                    ->setName1('Sender Company GmbH')
                                    ->setName2('Company Sender Person')
                                    ->setStreet('Residenzstraße')
                                    ->setHouseNo(1)
                                    ->setCountry('DE')
                                    ->setZipCode('80333')
                                    ->setCity('München')
                            )
                            ->setRecipient(
                                (new \Dpd\Business\AddressWithType())
                                    ->setAddressTypePrivate()
                                    ->setName1('Person Name')
                                    ->setStreet('Neue Mainzer Str.')
                                    ->setHouseNo('52-58')
                                    ->setCountry('DE')
                                    ->setZipCode('60311')
                                    ->setCity('Frankfurt am Main')
                            )
                            ->setIdentificationNumber('Your-Shipment-Id')
                            ->setMpsCustomerReferenceNumber1('Customer reference 1')
                    )
                    ->addParcel(
                        (new \Dpd\Business\Parcel())
                            ->setWeight(500)
                            ->setAddServiceParcelBox()
                    )
                    ->setProductAndServiceData(
                        (new \Dpd\Business\ProductAndServiceData())
                            ->setOrderTypeConsignment()
                            ->setFood(false)
                    )
            )
            ->addOrder(
                (new \Dpd\Business\ShipmentServiceData())
                    ->setGeneralShipmentData(
                        (new \Dpd\Business\GeneralShipmentData())
                            ->setProductDpdClassic()
                            ->setSendingDepot('0141')
                            ->setMpsWeight(500)
                            ->setMpsVolume(100 * 10 * 50)
                            ->setSender(
                                (new \Dpd\Business\AddressWithType())
                                    ->setAddressTypeCommercial()
                                    ->setName1('Sender Company GmbH')
                                    ->setName2('Company Sender Person')
                                    ->setStreet('Residenzstraße')
                                    ->setHouseNo(1)
                                    ->setCountry('DE')
                                    ->setZipCode('80333')
                                    ->setCity('München')
                            )
                            ->setRecipient(
                                (new \Dpd\Business\AddressWithType())
                                    ->setAddressTypePrivate()
                                    ->setName1('Person Name')
                                    ->setStreet('Neue Mainzer Str.')
                                    ->setHouseNo('52-58')
                                    ->setCountry('DE')
                                    ->setZipCode('60311')
                                    ->setCity('Frankfurt am Main')
                            )
                            ->setIdentificationNumber('Your-Return-Shipment-Id')
                            ->setMpsCustomerReferenceNumber1('Customer reference 1')
                    )
                    ->addParcel(
                        (new \Dpd\Business\Parcel())
                            ->setWeight(500)
                            ->setAddServiceParcelBox()
                            ->setReturns(true)
                    )
                    ->setProductAndServiceData(
                        (new \Dpd\Business\ProductAndServiceData())
                            ->setOrderTypeConsignment()
                            ->setFood(false)
                    )
            );

    $response = \Dpd\Api::me()->storeOrders($authentication, $storeOrders);
    
    if ($response instanceof \Dpd\Business\AuthenticationFault) {
        // authentication fault
        print_r($response);     
    } elseif ($response instanceof \Dpd\Business\StoreOrdersResponseType) {
    
        print_r($response);
        
        foreach ($response->getShipmentResponses() as $shipmentResponse) {
            if (
                $shipmentResponse instanceof \Dpd\Business\ShipmentResponse
                && $shipmentResponse->getParcelInformation() instanceof \Dpd\Business\ParcelInformationType
                && $shipmentResponse->getParcelInformation()->getParcelLabelNumber()
                && $shipmentResponse->getParcelInformation()->getOutput() instanceof \Dpd\Business\OutputType
                && $shipmentResponse->getParcelInformation()->getOutput()->getContent()
            ) {
                if ($shipmentResponse->getParcelInformation()->getOutput()->getFormat() == \Dpd\Business\OutputFormatType::TYPE_PDF) {
                    file_put_contents($shipmentResponse->getParcelInformation()->getParcelLabelNumber() . '.pdf', $shipmentResponse->getParcelInformation()->getOutput()->getContent());
                } elseif ($shipmentResponse->getParcelInformation()->getOutput()->getFormat() == \Dpd\Business\OutputFormatType::TYPE_MULTIPAGE_IMAGE) {
                    file_put_contents($shipmentResponse->getParcelInformation()->getParcelLabelNumber() . '.gif', $shipmentResponse->getParcelInformation()->getOutput()->getContent());
                }
            }
        }
    }
} catch(\Throwable $e) {
    // process exception
}

Example response for authentication fault:

Dpd\Business\AuthenticationFault Object
(
    [errorCode:protected] => LOGIN_5
    [errorMessage:protected] => The authtoken is invalid
)

Example response for incorrect request:

Dpd\Business\StoreOrdersResponseType Object
(
    [shipmentResponses:protected] => Array
        (
            [0] => Dpd\Business\ShipmentResponse Object
                (
                    [identificationNumber:protected] => Your-Shipment-Id
                    [faults:protected] => Dpd\Business\FaultCodeType Object
                        (
                            [faultCode:protected] => COMMON_7
                            [message:protected] => mpsWeight
                        )

                )

            [1] => Dpd\Business\ShipmentResponse Object
                (
                    [identificationNumber:protected] => Your-Return-Shipment-Id
                    [faults:protected] => Dpd\Business\FaultCodeType Object
                        (
                            [faultCode:protected] => COMMON_7
                            [message:protected] => mpsWeight
                        )

                )

        )

)

Example success response:

Dpd\Business\StoreOrdersResponseType Object
(
    [shipmentResponses:protected] => Array
        (
            [0] => Dpd\Business\ShipmentResponse Object
                (
                    [identificationNumber:protected] => Your-Shipment-Id
                    [mpsId:protected] => MPS0998505320867120210611
                    [parcelInformation:protected] => Dpd\Business\ParcelInformationType Object
                        (
                            [parcelLabelNumber:protected] => 09985053208671
                            [output:protected] => Dpd\Business\OutputType Object
                                (
                                    [format:protected] => MULTIPAGE_IMAGE
                                    [content:protected] => BINARY LABEL DATA
                                )
                        )
                )
            [1] => Dpd\Business\ShipmentResponse Object
                (
                    [identificationNumber:protected] => Your-Return-Shipment-Id
                    [mpsId:protected] => MPS0998505320867220210611
                    [parcelInformation:protected] => Dpd\Business\ParcelInformationType Object
                        (
                            [parcelLabelNumber:protected] => 09985053208672
                            [output:protected] => Dpd\Business\OutputType Object
                                (
                                    [format:protected] => MULTIPAGE_IMAGE
                                    [content:protected] => BINARY LABEL DATA
                                )
                        )
                )
        )
)

and labels will be saved in 09985053208666.gif and 09985053208667.gif files

Track parcel

\Dpd\Api::dev();
$response = null;

try {
    $authentication =
        (new \Dpd\Business\Authentication)
            ->setDelisId('sandboxdpd')
            ->setAuthToken('L***R')
            ->setMessageLanguage('en_US');

    $response = 
        \Dpd\Api::me()->getTrackingData(
            $authentication,
            new \Dpd\Business\GetTrackingData('09981122330100')
        );
    
    if ($response instanceof \Dpd\Business\AuthenticationFault) {
        // authentication fault
        print_r($response);  
    } elseif ($response instanceof \Dpd\Business\TrackingResult) {
        print_r($response);
    }
} catch(\Throwable $e) {
    print_r($e);
}

Example response for authentication fault:

Dpd\Business\AuthenticationFault Object
(
    [errorCode:protected] => LOGIN_5
    [errorMessage:protected] => The authtoken is invalid
)

Example response for unexisted :

Dpd\Business\AuthenticationFault Object
(
    [errorCode:protected] => LOGIN_5
    [errorMessage:protected] => The authtoken is invalid
)

Example success response:

Dpd\Business\TrackingResult Object
(
    [shipmentInfo:protected] => Dpd\Business\ShipmentInfo Object
        (
            [serviceDescription:protected] => Dpd\Business\ContentItem Object
                (
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => Your DPD service: 
                            [bold:protected] => 
                            [paragraph:protected] => 
                        )

                    [content:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => DPD CLASSIC C.O.D.
                            [bold:protected] => 
                            [paragraph:protected] => 
                        )

                    [linkTarget:protected] => 
                )
            [status:protected] => SHIPMENT
            [label:protected] => Dpd\Business\ContentLine Object
                (
                    [content:protected] => Shipment information
                    [bold:protected] => 1
                    [paragraph:protected] => 
                )
            [description:protected] => Dpd\Business\ContentItem Object
                (
                    [content:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => Details of your shipment
                            [bold:protected] => 
                            [paragraph:protected] => 
                        )
                    [linkTarget:protected] => 
                )
            [statusHasBeenReached:protected] => 
            [isCurrentStatus:protected] => 
            [showContactInfo:protected] => 
        )
    [statusInfo:protected] => Array
        (
            [0] => Dpd\Business\StatusInfo Object
                (
                    [status:protected] => ACCEPTED
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => Parcel handed to DPD
                            [bold:protected] => 1
                            [paragraph:protected] => 
                        )
                    [description:protected] => Dpd\Business\ContentItem Object
                        (
                            [content:protected] => Dpd\Business\ContentLine Object
                                (
                                    [content:protected] => DPD has received your parcel.
                                    [bold:protected] => 
                                    [paragraph:protected] => 
                                )
                            [linkTarget:protected] => 
                        )
                    [statusHasBeenReached:protected] => 
                    [isCurrentStatus:protected] => 1
                    [showContactInfo:protected] => 
                )
            [1] => Dpd\Business\StatusInfo Object
                (
                    [status:protected] => AT_SENDING_DEPOT
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => In transit
                            [bold:protected] => 1
                            [paragraph:protected] => 
                        )
                    [description:protected] => Dpd\Business\ContentItem Object
                        (
                            [content:protected] => Dpd\Business\ContentLine Object
                                (
                                    [content:protected] => The parcel is at the parcel dispatch centre.
                                    [bold:protected] => 
                                    [paragraph:protected] => 
                                )
                            [linkTarget:protected] => 
                        )
                    [statusHasBeenReached:protected] => 
                    [isCurrentStatus:protected] => 
                    [showContactInfo:protected] => 
                )
            [2] => Dpd\Business\StatusInfo Object
                (
                    [status:protected] => ON_THE_ROAD
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => At parcel delivery centre
                            [bold:protected] => 1
                            [paragraph:protected] => 
                        )
                    [description:protected] => Dpd\Business\ContentItem Object
                        (
                            [content:protected] => Dpd\Business\ContentLine Object
                                (
                                    [content:protected] => Your parcel is on its way to the parcel delivery centre.
                                    [bold:protected] => 
                                    [paragraph:protected] => 
                                )
                            [linkTarget:protected] => 
                        )
                    [statusHasBeenReached:protected] => 
                    [isCurrentStatus:protected] => 
                    [showContactInfo:protected] => 
                )
            [3] => Dpd\Business\StatusInfo Object
                (
                    [status:protected] => AT_DELIVERY_DEPOT
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => Parcel out for delivery
                            [bold:protected] => 1
                            [paragraph:protected] => 
                        )
                    [description:protected] => Dpd\Business\ContentItem Object
                        (
                            [content:protected] => Dpd\Business\ContentLine Object
                                (
                                    [content:protected] => At parcel delivery centre.
                                    [bold:protected] => 
                                    [paragraph:protected] => 
                                )
                            [linkTarget:protected] => 
                        )
                    [statusHasBeenReached:protected] => 
                    [isCurrentStatus:protected] => 
                    [showContactInfo:protected] => 
                )
            [4] => Dpd\Business\StatusInfo Object
                (
                    [status:protected] => DELIVERED
                    [label:protected] => Dpd\Business\ContentLine Object
                        (
                            [content:protected] => Parcel delivered
                            [bold:protected] => 1
                            [paragraph:protected] => 
                        )
                    [description:protected] => Dpd\Business\ContentItem Object
                        (
                            [content:protected] => Dpd\Business\ContentLine Object
                                (
                                    [content:protected] => Your parcel has been delivered successfully.
                                    [bold:protected] => 
                                    [paragraph:protected] => 
                                )

                            [linkTarget:protected] => 
                        )
                    [statusHasBeenReached:protected] => 
                    [isCurrentStatus:protected] => 
                    [showContactInfo:protected] => 
                )
        )
)

blobswop/dpd-php-api 适用场景与选型建议

blobswop/dpd-php-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.52k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「wrapper」 「shipping」 「tracking」 「dpd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 blobswop/dpd-php-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blobswop/dpd-php-api 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 3.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-11