firstred / myparcelbe-sdk
此包通过API向MyParcel发送和接收数据。
Requires
- php: >= 5.3.3
- ext-curl: *
- ext-json: *
- php-curl-class/php-curl-class: ^8.5
Requires (Dev)
- phpunit/phpunit: ^4.8.36 || ^5.7.27
This package is auto-updated.
Last update: 2020-01-02 18:06:19 UTC
README
这是MyParcel PHP库的非官方PHP 5.3.3+端口。
如果您可以运行更高版本的PHP,请避免使用此非官方端口!
MyParcel SDK
请,如果您使用此存储库,请星标此存储库。⭐️
使用composer的安装
此SDK使用composer。
Composer是PHP中依赖管理的工具。它允许您声明项目所依赖的库,并且它将为您安装(更新)它们。
有关如何使用/安装composer的更多信息,请访问: https://github.com/composer/composer
要将MyParcel SDK安装到您的项目中,只需
$ composer require myparcelbe/sdk
不使用composer的安装
如果您没有使用composer的经验,也可以在不使用composer的情况下使用SDK。
您可以在项目的发布页面下载zip文件。
- 下载包zip文件(SDKvx.x.x.zip)。
- 解压缩zip文件的内容,并将vendor目录上传到您的服务器。
- 在您的项目中,需要文件src/AutoLoader.php
- 现在您可以在项目中使用SDK了
要求
MyParcel SDK适用于php版本5.6,7.x。还需要安装php curl扩展。
快速入门和示例
$myParcelCollection = new \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203') ->setCountry('BE') ->setPerson('Piet Hier') ->setCompany('Piet BV') ->setFullStreet('Plein 1945 55b') ->setPostalCode('2231JE') ->setCity('Amsterdam') ->setEmail('test@test.nl'); $myParcelCollection ->addConsignment($consignment) ->setPdfOfLabels() ->downloadPdfOfLabels() ->setUserAgent('name_of_cms', '1.0');
可用方法
$myParcelCollection = new \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203') ->setCountry('BE') ->setPerson('Piet Hier') ->setCompany('Piet BV') ->setFullStreet('Plein 1945 55b') ->setPostalCode('2231JE') ->setPackageType(1) ->setCity('Amsterdam') ->setEmail('test@test.nl') ->setPhone('+31 (0)634213465') ->setLargeFormat(true) ->setOnlyRecipient(true) ->setSignature(true) ->setReturn(true) ->setInsurance(250) ->setLabelDescription('Order 10034'); $myParcelCollection ->addConsignment($consignment)
用户代理
为了让我们了解您从哪个CMS系统建立连接,您应该发送User-Agent。如果您使用的是已知的CMS系统,则这是必需的。您必须发送CMS系统的名称,后跟版本号。版本不是必需的。
->setUserAgent('name_of_cms', '1.0')
提交完整地址
->setFullStreet('Plein 1945 55b')
分块提交地址
->setStreet('Plein 1945') ->setNumber((string)55) ->setBoxNumber('b')
创建概念
$myParcelCollection->createConcepts();
下载标签
$myParcelCollection->setPdfOfLabels(); $myParcelCollection->downloadPdfOfLabels();
获取标签链接
$myParcelCollection ->setLinkOfLabels() ->getLinkOfLabels()
MyParcel托运件ID
如果您不使用setReferenceId()
,在创建概念时也可以使用MyParcelConsignmentId:在调用setPdfOfLabels()
、setLinkOfLabels()
和createConcepts()
之后,可以将API ID保存到数据库中。使用此ID可以轻松检索最新状态。
$consignment->getMyParcelConsignmentId();
获取状态
在调用setPdfOfLabels()
、setLinkOfLabels()
和createConcepts()
后,您可以获取状态。
$status = $consignment->getStatus();
获取条形码
在调用setPdfOfLabels()
和setLinkOfLabels()
后,条形码可用。
$barcode = $consignment->getBarcode();
多件货物
要创建多个托运单或获取包含多个托运单的一个PDF,请设置多个托运单。这更快且更简洁。
$myParcelCollection = new \MyParcelBE\Sdk\src\Helper\MyParcelCollection(); foreach ($yourShipments as $yourShipment) { $consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId($yourShipment->getOrderId() ->setName('Piet Hier'); /** @todo; set all info */ $myParcelCollection ->setUserAgent('name_of_cms', '1.0') ->addConsignment($consignment) }
之后
在新的请求中,您可以再次获取所有数据。
$consignment = (new \MyParcelBE\Sdk\src\Model\Repository\MyParcelConsignmentRepository()) ->setApiKey('api_key_from_MyParcel_backoffice') ->setReferenceId('Order 1203'); // or setMyParcelConsignmentId(123456) $myParcelCollection ->addConsignment($consignment) ->setLatestData(); $consignments = $myParcelCollection ->getConsignments(); $firstConsignment = $consignments[0]; $status = $firstConsignment->getStatus(); $barcode = $firstConsignment->getBarcode();
贡献
- 查找开放问题或打开新问题,以开始围绕错误或功能进行讨论。
- 在GitHub上Fork存储库以开始做出您的更改。
- 为新的功能或暴露错误的特性编写一个或多个测试。
- 进行代码更改以实现功能或修复错误。
- 发送拉取请求以合并和发布您的更改。