tsekka/omniva

快速连接您的PHP应用程序与Omniva,一个服务于爱沙尼亚、拉脱维亚和立陶宛的波罗的海货运公司。通过SOAP发送XML数据。通过电子邮件生成Omniva订单,输出跟踪号并输出包裹标签。

0.1.4 2023-07-29 07:49 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Omniva是一家服务于波罗的海国家爱沙尼亚、拉脱维亚和立陶宛的货运公司。使用此包,您将能够生成包裹并请求运单。

功能

  • 生成货运(请求类型响应于businessToClientMsgRequest)并获取货运条形码。
  • 获取货运条形码(可用于显示跟踪代码或获取运单)。
  • 请求通过Omniva服务器发送的运单电子邮件。
  • 以文件形式获取包裹标签。

安装

您可以通过composer安装此包

composer require tsekka/omniva

使用示例

生成货运

此示例假设您将使用Omniva的包裹机作为目的地,并且您知道其邮政编码。

包裹机的列表以json、xml和csv格式轻松可用。请参阅Omniva手册以获取本例中使用的目的地点和服务代码的列表。

    use Tsekka\Omniva\Client;
    use Tsekka\Omniva\Parcel;
    use Tsekka\Omniva\Address;
    use Tsekka\Omniva\PickupPoint;

    /**
     * Set your authentication details.
     */
    $client = new Client(
        username: 'your Omniva web service username',
        password: 'your Omniva web service password'
    );

    /**
     * Set & define delivery service, 
     * pickup point's information 
     * and additional services. 
     */
    $parcel = new Parcel(
        deliveryService: 'PA'
    );
    $pickupPoint = new PickupPoint(
        offloadPostcode: 96094,
        type: 0
    );
    $parcel
        ->addAdditionalService('ST')
        ->addAdditionalService('SF');

    /**
     * Set & define receiver and returnee.
     */
    $receiver = new Address();
    $receiver->pickupPoint = $pickupPoint;
    $receiver->name = 'Jane Doe';
    $receiver->mobile = '+3725511223';
    $receiver->email = 'client@example.com';
    $returnee = new Address();
    $returnee->country = 'EE';
    $returnee->name = 'John Roe';
    $returnee->mobile = '+3725566778';
    $returnee->email = 'returnee@example.com';
    $returnee->postcode = '80040';
    $returnee->deliverypoint = 'PARNU';
    $returnee->street = 'Savi 20';
    $returnee->country = 'EE';
    $parcel->receiver = $receiver;
    $parcel->returnee = $returnee;

    /**
     * Generate the shipment & get the barcode
     */
    $barcode = $client->createShipment($parcel);

获取运单

    /**
     * Request the label to be emailed to you from Omniva's server
     */
    $client->sendLabel($barcode, 'business@example.com');

    /**
     * Or get the content of pdf file & save or output it
     */
    $fileData = $client->getLabel($barcode);
    $fileName = "label_{$barcode}.pdf";
    file_put_contents(storage_path() . "/{$fileName}", base64_decode($fileData));
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    echo base64_decode($fileData);

测试

composer test

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

贡献

欢迎贡献,并将获得认可。

安全漏洞

请通过电子邮件 pintek@pintek.ee 报告安全漏洞。

鸣谢

许可

MIT许可(MIT)。请参阅许可文件以获取更多信息。