shipmondo/shipmondo_php_sdk

Shipmondo官方PHP库

3.5.0 2023-02-10 12:44 UTC

This package is auto-updated.

Last update: 2024-09-10 16:25:34 UTC


README

此SDK支持Shipmondo API v3。

规范:https://app.shipmondo.com/api/public/v3/specification

注意:如果您想从pakkelabels-php-sdk升级,请参阅本节

入门

以下是一个简单的PHP脚本,说明了开始使用所需的最小代码量。

<?php
  try {
    $client = new Shipmondo('api_user', 'api_key');
  } catch (ShipmondoException $e) {
    echo $e->getMessage();
  }
?>

创建好$client对象后,您就可以开始使用API了。

示例

获取当前余额

<?php
  echo $client->getAccountBalance();
?>

获取未决付款请求

<?php
  $params = [
    'created_at_min' => '2019-08-22',
    'page' => 1
  ];
  echo $client->getAccountPaymentRequests($params);
?>

获取可用产品

<?php
  $params = [
    'country_code' => 'DK',
    'carrier_code' => 'gls',
    'page' => 1
  ];
  echo $client->getProducts($params);
?>

支持分页

获取可用/最近的取件点

<?php
  $params = [
    'country_code' => 'DK',
    'carrier_code' => 'gls',
    'zipcode' => '5000'
  ];
  echo $client->getPickupPoints($params);
?>

获取货运

<?php
  $params = [
    'page' => 1,
    'carrier_code' => 'dao'
  ];
  echo $client->getShipments($params);
?>

支持分页

通过id获取货运

<?php
  $id = 5545625;
  echo $client->getShipment($id);  
?>

获取货运的标签

<?php
  $shipment_id = 5545625;
  $params = [
    'label_format' => '10x19_pdf'
  ];
  echo $client->getShipmentLabels($shipment_id, $params);  
?>

创建货运

<?php
  $params = [
    "test_mode" => true,
    "own_agreement" => true,
    "label_format" => "a4_pdf",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => [
      "name" => "Shipmondo ApS",
      "address1" => "Strandvejen 6B",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "firma@email.dk",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ],
    "receiver" => [
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "lene@email.dk",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    ],
    "parcels" => [
      [
        "weight" => 1000
      ]
    ],
  ];
  echo $client->createShipment($params);
?>

获取打印队列条目

<?php
  $params = [
    'page' => 1
  ];
  echo print_r($client->getPrintQueueEntries($params);
?>

获取退货端口

<?php
  $params = [
    'page' => 1
  ];
  echo $client->getReturnPortals($params);  
?>

通过id获取退货端口

<?php
  $id = 4766;
  echo $client->getReturnPortal($id);  
?>

获取退货端口的退货货运

<?php
  $return_portal_id = 4766;
  $params = [
    'page' => 1
  ];
  echo $client->getReturnPortalShipments($return_portal_id, $params);  
?>

支持分页

获取导入的货运

<?php
  $params = [
    'page' => 1
  ];
  echo $client->getImportedShipments($params);
?>

支持分页

通过id获取导入的货运

<?php
  $id = 75545625;
  echo $client->getImportedShipment($id);
?>

创建导入的货运

<?php
  $params = [
    "carrier_code" => "gls",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => [
      "name" => "Shipmondo ApS",
      "address1" => "Strandvejen 6B",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "firma@email.dk",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ],
    "receiver" => [
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "lene@email.dk",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    ]
  ];
  echo $client->createImportedShipment($params);
?>

通过id更新导入的货运

<?php
  $id = 75545625;
  $params = [
    "carrier_code" => "gls",
    "product_code" => "GLSDK_HD",
    "service_codes" => "EMAIL_NT,SMS_NT",
    "order_id" => "10001",
    "reference" => "Webshop 10001",
    "sender" => [
      "name" => "Shipmondo ApS",
      "address1" => "Strandvejen 6B",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5240",
      "city" => "Odense NØ",
      "attention" => null,
      "email" => "firma@email.dk",
      "telephone" => "70400407",
      "mobile" => "70400407"       
    ],
    "receiver" => [
      "name" => "Lene Jensen",
      "address1" => "Vindegade 112",
      "address2" => null,
      "country_code" => "DK",
      "zipcode" => "5000",
      "city" => "Odense C",
      "attention" => null,
      "email" => "lene@email.dk",
      "telephone" => "50607080",
      "mobile" => "50607080",
      "instruction" => null
    ]
  ];
  echo $client->updateImportedShipment($id, $params);
?>

通过id删除/存档导入的货运

<?php
  $id = 75545625;
  echo $client->deleteImportedShipment($id);
?>

从pakkelabels-php-sdk迁移

如果您已经使用pakkelabels-php-sdk库,并且想升级到shipmondo_php_sdk,您必须按照以下步骤操作

  • 将任何require中的Pakkelabels.php更改为Shipmondo.php
  • 将对PakkelabelsPakkelabelsException类的引用更改为ShipmondoShipmondoException
  • 所有函数调用都必须改为驼峰命名法,例如:create_shipment -> createShipment
  • 所有GET函数调用必须在前面添加get,以及改为驼峰命名法,例如:account_balance -> getAccountBalance