boxtale / php-library
Boxtal v1 API 的 PHP 库
dev-master
2023-09-20 09:32 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2024-09-26 00:12:28 UTC
README
这个 PHP 库旨在提供 Boxtal v1 API 的 PHP 实现。
安装
要安装库,只需
$ composer require boxtale/php-library
要求
PHP 库与 PHP 5.4 及以上版本兼容。
为了使用 API,您需要在 Boxtal 上创建一个(免费)用户账户。为了测试,您可以创建一个 免费测试账户。
库内容
该包包含 5 个主要目录
- Emc - 包含与 API 交互的类
- config - 包含配置和自动加载文件
- samples - 包含使用库的示例文件
- test - 一个测试您的开发环境是否拥有库所使用的所有扩展的文件
快速开始和示例
首先,在 config/config.php 文件中填写您的凭据和工作环境。
define("EMC_MODE", "test"); if (EMC_MODE == "prod") { define("EMC_USER", "myLogin"); define("EMC_PASS", "myPassword"); } else { define("EMC_USER", "myLogin"); define("EMC_PASS", "myPassword"); }
获取报价
以下是获取报价所需的元素
- 您的运输类型:"encombrant"(大件包裹)、"colis"(包裹)、"palette"(托盘)、"pli"(信封)
- 您的内容类型 ID
- 发货人的国家、城市、地址和类型(公司或个人)
- 收件人的国家、城市和类型(公司或个人)
- 收货日期(不包括周日和节假日)
- 您的运输内容价值(跨境报价)
require __DIR__ . '/vendor/autoload.php'; // shipper address $from = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '38400', 'ville' => "Saint Martin d'Hères", 'type' => 'entreprise', 'adresse' => '13 Rue Martin Luther King' ); // recipient's address $to = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '33000', 'ville' => 'Bordeaux', 'type' => 'particulier', // accepted values are "entreprise" or "particulier" 'adresse' => '24, rue des Ayres' ); /* Parcels informations */ $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array( 'poids' => 1, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8 ) ) ); $additionalParams = array( 'collecte' => date("Y-m-d"), 'delay' => 'aucun', 'content_code' => 10120, 'valeur' => "42.655" ); $lib = new \Emc\Quotation(); $lib->getQuotation($from, $to, $parcels, $additionalParams); // The offers list is available on the array : $lib->offers if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->offers); } else { handle_errors($lib); }
下订单
下订单的过程与获取报价相同。唯一不同的是您需要发送的额外参数。
对于发货人和收件人,您需要提供电话号码、姓名和姓氏。对于运输,根据选择的承运人,您可能需要提供取货可用时间、交货和/或取货包裹点。所有国际运输都需要一个 object.valeur 参数(其中 object 是运输类型:"encombrant"(大件包裹)、"colis"(包裹)、"palette"(托盘)、"pli"(信封))。
require __DIR__ . '/vendor/autoload.php'; // shipper address $from = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '75002', 'ville' => 'Paris', 'type' => 'entreprise', // accepted values are "particulier" or "entreprise" 'adresse' => '15, rue Marsollier', 'civilite' => 'M', // accepted values are "M" (sir) or "Mme" (madam) 'prenom' => 'John', 'nom' => 'Snow', 'societe' => 'Boxtale', 'email' => 'jsnow@boxtale.com', 'tel' => '0606060606', 'infos' => 'Some informations about this address' ); // Recipient address $to = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '13002', 'ville' => 'Marseille', 'type' => 'particulier', // accepted values are "particulier" or "entreprise" 'adresse' => '1, rue Chape', 'civilite' => 'Mme', // accepted values are "M" (sir) or "Mme" (madam) 'prenom' => 'Jane', 'nom' => 'Doe', 'email' => 'jdoe@boxtale.com', 'tel' => '0606060606', 'infos' => 'Some informations about this address' ); /* Parcel information */ $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array( 'poids' => 5, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8 ) ) ); $additionalParams = array( 'collecte' => date('Y-m-d'), 'delai' => "aucun", 'assurance.selection' => false, // whether you want an extra insurance or not 'url_push' => 'www.my-website.com/push.php&order=', 'content_code' => 40110, 'colis.description' => "Tissus, vêtements neufs", 'valeur' => "42.655", 'depot.pointrelais' => 'CHRP-POST', 'operator' => 'CHRP', 'service' => 'Chrono18' ); // Prepare and execute the request $lib = new \Emc\Quotation(); $orderPassed = $lib->makeOrder($from, $to, $parcels, $additionalParams); if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->order); } else { handle_errors($lib); }
获取可用的内容类型列表
使用 API,您可以获取可用内容类型的列表,您将能够在您的模块中使用这些类型。"内容类型"是您所运输的内容的性质。
require __DIR__ . '/vendor/autoload.php'; $lib = new \Emc\ContentCategory(); $lib->getCategories(); // load all content categories $lib->getContents(); // load all content types // The content categories list is available on the array : $lib->categories // The content types list is available on the array : $lib->contents if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->categories); print_r($lib->contents); } else { handle_errors($lib); }
5. 获取国家列表
使用 Boxtal API 发送的订单使用国家 ISO 代码。目前,系统仅允许从法国运往国外,不允许从国外运往法国。以下是获取国家列表的方法。
$lib = new \Emc\Country(); $lib->getCountries(); // The countries list is available on the array : $lib->countries if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->countries); } else { handle_errors($lib); }