human018/laravel-aus-post

Laravel 与澳大利亚邮政API的集成

0.0.3 2024-02-29 06:43 UTC

This package is auto-updated.

Last update: 2024-09-29 07:55:56 UTC


README

描述

这是一个专为与澳大利亚邮政API接口而设计的Laravel包,提供了一种简单高效的方式将澳大利亚邮政API服务集成到您的Laravel应用中。

重要:此包仍在开发中。

要求

  • PHP 8.1或更高版本
  • Laravel框架9.52.4或更高版本

安装

使用包管理器composer安装Laravel Australia Post Package。

composer require human018/laravel-aus-post

安装后,将您的澳大利亚邮政API密钥添加到您的.env文件中

AUSPOST_KEY=...

用法

该包使用以下类和方法链从澳大利亚邮政API请求邮寄信息。

use Human018\LaravelAusPost\AusPost

至少需要提供起始和目的地邮编、邮寄类型以及要使用的邮寄服务。

必须始终首先声明您希望使用的邮寄类型 - 国内还是国际。

AusPost::domestic()
AusPost::international()

之后,可以链式调用其他方法

AusPost::domestic()
->parcelCalculate() // Tells the service we will be calculating for a Parcel (as opposed to a letter)
->fromPostcode // 4 digit origin postcode
->toPostcode // 4 digit destination postcode
->width() // mm
->height() // mm
->length() // mm
->weight() // grams
->usingService() // Provide one of the below service types
// AUS_PARCEL_EXPRESS
// AUS_PARCEL_REGULAR
->get() // Retrieves the result

国内邮寄示例

Human018\LaravelAusPost\AusPost::domestic()->parcelCalculate()->fromPostcode(3000)->toPostcode(2000)->usingService('AUS_PARCEL_REGULAR')->get();

结果

[
    "postage_result" => [
      "service" => "Parcel Post",
      "delivery_time" => "Delivered in 2-3 business days",
      "total_cost" => "10.60",
      "costs" => [
        "cost" => [
          "item" => "Parcel Post",
          "cost" => "10.60",
        ],
      ],
    ],
    "service" => [
      "service" => "AUS_PARCEL_REGULAR",
      "name" => "Regular Post",
      "description" => "Australia Post: Regular Parcel",
      "delivery_time" => "3-5 business days",
    ],
  ]