allekurier/api_v1

AlleKurier api

v1.2.6 2020-04-01 11:17 UTC

This package is auto-updated.

Last update: 2024-09-20 20:11:01 UTC


README

需求

  • PHP 5.4.0 或更高版本;
  • ext-json;
  • ext-curl;

安装

Composer

composer require allekurier/api_v1

Zip

require __DIR__ . '/my_path/allekurier/api_v1/AutoLoader.php';

allekurier\api_v1\AutoLoader::init(__DIR__ . '/my_path');

使用

准备API

$credentials = new allekurier\api_v1\Credentials('login', 'hasło');
$api = new allekurier\api_v1\AKAPI($credentials);

创建订单

函数返回任务HID、运单号、当前状态和运费。

正确的输出是状态为ready。如果返回的状态等于processing,则需要记录任务HID并在指定的时间间隔内检查(getStatus函数)任务是否已处理,以继续处理(获取和打印文档)。状态processing的原因可能是承运商系统故障。

$order = new allekurier\api_v1\model\Order(
    'nazwa usługi',
    'typ opakowania',
    'opis przesyłki',
    'metoda odbioru',
    'kwota pobrania',
    'kwota ubezpieczenia',
    'numer referencyjny',
    'wartość towaru',
    'voucher'
);

$sender = new allekurier\api_v1\model\Sender(
    'nazwa nadawcy',
    'osoba kontaktowa',
    'kod pocztowy',
    'adres',
    'miasto',
    'telefon',
    'email',
    'kod państwa',
    'punkt przewoźnika',
    'numer konta bankowego'
);

$recipient = new allekurier\api_v1\model\Recipient(
    'nazwa odbiorcy',
    'osoba kontaktowa',
    'kod pocztowy',
    'adres',
    'miasto',
    'telefon',
    'email',
    'kod państwa',
    'punkt przewoźnika',
    'kod stanu'
);

// Wymagany gdy Order - metoda odbioru = register
$pickup = new allekurier\api_v1\model\Pickup(
    'data odbioru',
    'od godz',
    'do godz'
);

$packages = new allekurier\api_v1\model\Packages([
    new allekurier\api_v1\model\Package('waga', 'szerokość', 'wysokość', 'długość', 'czy standardowa')
]);

$additionalServices = [
    'sms',
    'email_notif_delivered'
];

$action = new allekurier\api_v1\action\CreateOrderAction(
    $order,
    $sender,
    $recipient,
    $packages,
    $pickup,
    $additionalServices
);

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    echo $response->number();
    echo $response->hid();
    echo $response->cost();
    echo $response->status();
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/order_create \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &Order%5Bpackage%5D=*typ_opakowania*
      &Order%5Bcod%5D=*kwota_pobrania*
      &Order%5Binsurance%5D=*kwota_ubezpieczenia*
      &Order%5Bdelivery%5D=*metoda_odbioru*
      &Order%5Bservice%5D=*nazwa_uslugi*
      &Order%5Bdescription%5D=*opis_przesylki*
      &Order%5Bvalue%5D=*wartosc_towaru*
      &Sender%5Bcountry%5D=*kod_kraju*
      &Sender%5Bphone%5D=*telefon*
      &Sender%5Baddress%5D=*adres*
      &Sender%5Bpostal_code%5D=*kod_pocztowy*
      &Sender%5Bperson%5D=*osoba_kontaktowa*
      &Sender%5Bcity%5D=*miasto*
      &Sender%5Bemail%5D=*email*
      &Sender%5Bname%5D=*nadawca*
      &Sender%5Bbank_account%5D=*numer_banku_do_zwrotu_pobrania*
      &Sender%5Bdropoff_point%5D=*kod_punktu_przewoznika*
      &Recipient%5Bcountry%5D=*kod_kraju*
      &Recipient%5Bpostal_code%5D=*kod_pocztowy*
      &Recipient%5Bphone%5D=*telefon*
      &Recipient%5Bcity%5D=*miasto*
      &Recipient%5Bname%5D=*odbiorca*
      &Recipient%5Bperson%5D=*osoba_kontaktowa*
      &Recipient%5Baddress%5D=*adres*
      &Recipient%5Bemail%5D=*email*
      &Packages%5B0%5D%5Bweight%5D=*waga_paczki*
      &Packages%5B0%5D%5Bheight%5D=*wysokosc_paczki*
      &Packages%5B0%5D%5Bwidth%5D=*szerokosc_paczki*
      &Packages%5B0%5D%5Blength%5D=*dlugosc_paczki*
      &Packages%5B0%5D%5Bcustom%5D=*czy_standardowa*
      &Pickup%5Bdate%5D=*data*
      &Pickup%5Bfrom%5D=*od_godz*
      &Pickup%5Bto%5D=*do_godz*
      &Services%5B0%5D=*nazwa_uslugi*'
响应
{
    "Error":[],
    "Response":{
        "hid":"",
        "number":null,
        "cost":"12.76",
        "status":"processing"
    }
}

获取快递当前状态

根据订单号返回订单的基本信息。用于获取订单历史中的最后一条事件(状态)、运单号和追踪信息,以及日期(创建、寄出、送达)。

$action = new allekurier\api_v1\action\GetOrderStatusAction('hid przesyłki');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    echo $response->hid();
    echo $response->number();
    echo $response->traceNumber();
    echo $response->created();
    echo $response->sent();
    echo $response->delivered();
    echo $response->date();
    echo $response->name();
    echo $response->status();
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/order_status \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &hid=*hid*'
响应
{
    "Error": [],
    "Response": {
        "Order": {
            "hid": "",
            "number": null,
            "trace_number": null,
            "created": "2017-11-16 13:39:58",
            "sent": null,
            "delivered": null,
            "status": "canceled"
        },
        "Event": {
            "date": "2017-11-16 13:41:06",
            "status": "canceled",
            "name": "Anulowane"
        }
    }
}

获取运单

获取打印文档。函数返回编码后的(base64)pdf格式的运单列表。对于DPD,默认返回的是货物交接协议。只有在订单状态设置为ready时才能打印文档。

$action = new allekurier\api_v1\action\GetOrderLabelAction(
    'numer przesyłki', 
    'czy pobierać małe etykiety?' // true/false (parametr opcjonalny)
);

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    file_put_contents('my_path/label.pdf', $response->label());
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/order_label \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &number=*numer_przesylki*'
响应
{
    "Error":[],
    "Response":{
        "Order":{
            "hid":"",
            "number":"",
            "status":"ready"
        },
        "label":""
    }
}

获取快递历史

追踪快递。返回每个事件的日期、代码和描述。此外,还提供任务HID、创建日期、实际寄出和送达(或退回给发件人)的日期。返回事件数组事件

$action = new allekurier\api_v1\action\GetOrderHistoryAction('numer przesyłki');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    foreach ($response->history() as $event) {
        echo $event->date();
        echo $event->name();
        echo $event->status();
    }
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/order_history \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &number=*numer_przesylki*'
响应
{
    "Error": [],
    "Response": {
        "Order": {
            "hid": "",
            "number": "",
            "created": "2017-11-14 11:49:11",
            "sent": null,
            "delivered": null
        },
        "Event": [
            {
                "date": "2017-11-14 11:49:11",
                "status": "created",
                "name": "Zlecenie utworzone"
            },
            ...
        ]
    }
}

取消订单

根据订单号取消订单。UPS的运单必须无条件取消,即使快递员没有取件(尽管仍会收取运输费!)。我们假设无论承运商是谁,运单都必须取消。取消运单会导致取消该位置的接收订单。

$action = new allekurier\api_v1\action\CancelOrderAction('numer przesyłki');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    if ($response->isCanceled()) {
        echo 'Anulowane';
    }
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/order_cancel \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &number=*numer_przesylki*'
响应
{
    "Error": [],
    "Response": {
        "status": 1
    }
}

获取服务

方法返回给定数据的服务和费用。返回服务数组服务

$order = allekurier\api_v1\model\Order::createForPricing(
    'typ opakowania',
    'kwota pobrania',
    'kwota ubezpieczenia'
);

$sender = allekurier\api_v1\model\Sender::createForPricing(
    'kod państwa',
    'kod pocztowy tylko dla palet'
);

$recipient = allekurier\api_v1\model\Recipient::createForPricing(
    'kod państwa',
    'kod pocztowy tylko dla palet'
);

$packages = new allekurier\api_v1\model\Packages([
    new allekurier\api_v1\model\Package('waga', 'szerokość', 'wysokość', 'długość', 'czy standardowa')
]);

$action = new allekurier\api_v1\action\GetServicesAction($order, $sender, $recipient, $packages);

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    foreach ($response->services() as $service) {
        echo $service->carrierCode();
        echo $service->carrierName();
        echo $service->code();
        echo $service->name();
        echo $service->net();
        echo $service->gross();
    }
}

获取附加服务

方法返回给定服务提供的附加服务和费用。返回附加服务数组附加服务

$action = new allekurier\api_v1\action\GetAdditionalServicesAction('nazwa uslugi', 'typ opakowania');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    foreach ($response->services() as $service) {
        echo $service->code();
        echo $service->name();
        echo $service->net();
    }
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/additional_services \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &service=*kod_uslugi*
      &package=*typ_opakowania*'
响应
{
    "Error": [],
    "Response": {
        "cod_instant": {
            "name": "Pobranie Natychmiastowe (1 dzień)",
            "price": "2.00"
        },
        "rod": {
            "name": "Zwrot dokumentów",
            "price": "13.00"
        }
    }
}

获取收货时间

方法返回特定邮编下承运商可能的取件时间。数组“from”定义取件时间窗口的开始时间,数组“to”包含可能的结束时间,数值以从午夜开始计算的秒数表示,例如11:00 = 11 * 3600 = 39600。返回日期数组取件日期

$action = new allekurier\api_v1\action\GetPickupDatesAction('przewoźnik', 'kod pocztowy', 'kod państwa');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    foreach ($response->dates() as $date) {
        echo $date->date();
        echo $date->description();
        var_dump($date->from());
        var_dump($date->to());
    }
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/pickup_dates \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &carrier=*przewoznik*
      &postal_code=*kod_pocztowy*
      &country=*kod_kraju*'
响应
{
    "Error": [],
    "Response": [
        {
            "date": "2017-11-16",
            "description": "Dzisiaj",
            "from": {
                "41400": "11:30",
                "43200": "12:00"
            },
            "to": {
                "57600": "16:00"
            },
            "to_minima": {
                "41400": 57600,
                "43200": 57600
            },
            "call_to": 43200,
            "class": "todayPickupDate",
            "call_to_formatted": "12:00"
        },
        ...
    ]
}

获取承运人点

方法返回从指定邮编处选择的承运商所在区域的点。返回点数组投放点

$action = new allekurier\api_v1\action\GetDropoffPointsAction('przewoźnik', 'kod pocztowy');

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    foreach ($response->points() as $point) {
        echo $point->id();
        echo $point->latitude();
        echo $point->longitude();
        echo $point->name();
        echo $point->code();
        echo $point->address();
        echo $point->postalCode();
        echo $point->image();
        echo $point->openHours();
        echo $point->isSupportCod();
    }
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/access_points \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*
      &carrier=*przewoznik*
      &postal_code=*kod_pocztowy*'
响应
{
    "Error":[],
    "Response":{
        "Coordinates":{
            "longitude":"",
            "latitude":""
        },
        "AccessPoints":[
            {
                "AccessPoints":{
                    "id":"",
                    "latitude":"",
                    "longitude":"",
                    "code":"",
                    "name":"",
                    "address":"",
                    "address2":null,
                    "postal_code":"",
                    "city":"",
                    "image_url":null,
                    "open_hours":null,
                    "cod":"0"
                },
                "0":{
                    "diff":""
                }
            },
            ...
        ]
    }
}

获取用户余额

方法返回用户账户余额

$action = new allekurier\api_v1\action\GetUserBalanceAction;

$response = $api->call($action);

if ($response->hasErrors()) {
    var_dump($response->getErrors());
} else {
    echo $response->balance();
}
cURL
curl -X POST \
  https://allekurier.pl/api_v1/user_balance \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d 'User%5Bemail%5D=*email*
      &User%5Bpassword%5D=*haslo*'
响应
{
    "Error": [],
    "Response": [
        {
            "User": {
                "hid": "XXXXXX",
                "balance": "0.00",
                "free": "0.00"
            }
        }
    ]
}

模型

请求

订单
发件人 - S / 收件人 - R
取件
包裹(《包装类型》)

响应

服务
附加服务
投放点
取件日期
事件

词典

包装类型 - package

承运商