aadshalshihry / aramex
用于集成 Aramex API 的包
dev-main
2024-02-16 22:05 UTC
This package is auto-updated.
Last update: 2024-09-16 23:25:39 UTC
README
安装
您可以通过 Composer 安装此包。
composer require aadshalshihry/aramex
使用以下命令发布您的 aramex.php 配置文件:
php artisan vendor:publish --provider="Aadshalshihry\Aramex\AramexServiceProvider" --tag="aramex"
然后,将配置/aramex.php 文件中的 aramex 配置更改
'ENV' => 'TEST', //TEST|LIVE 'TEST' => [ 'AccountNumber' => '11111', 'UserName' => 'username@aramex.com', 'Password' => '123456', 'AccountPin' => '122334', 'AccountEntity' => 'EGY', 'AccountCountryCode' => 'EG', 'Version' => 'v1' ],
用法
创建取货
use Aadshalshihry\Aramex\Aramex; $data = Aramex::createPickup([ 'name' => 'name', 'cell_phone' => '+123123123', 'phone' => '+123123123', 'email' => 'myEmail@gmail.com', 'city' => 'Alexandria', 'country_code' => 'EG', 'zip_code'=> 21532, 'line1' => 'The line1 Details', 'line2' => 'The line2 Details', 'line3' => 'The line2 Details', 'pickup_date' => time() + 75000, 'ready_time' => time() + 80000, 'last_pickup_time' => time() + 85000, 'closing_time' => time() + 90000, 'status' => 'Ready',//Pending 'pickup_location' => 'some location', 'weight' => 123, 'volume' => 1 ]); // extracting GUID if (!$data->error) $guid = $data->pickupGUID;
- 注意:保存此 'guid',将在下一个服务中使用它
取消取货
use Aadshalshihry\Aramex\Aramex; //get $guid from createPickup function $response = Aramex::cancelPickup($guid,$cancel_reason = '');
创建货运
use Aadshalshihry\Aramex\Aramex; $callResponse = Aramex::createShipment([ 'shipper' => [ 'name' => 'name', 'email' => 'myEmail@gmail.com', 'phone' => '+123123123', 'cell_phone' => '+123123123', 'country_code' => 'EG', 'city' => 'Alexandria', // 'zip_code' => 21532, 'line1' => 'Line1 Details', 'line2' => 'Line2 Details', 'line3' => 'Line3 Details', ], 'consignee' => [ 'name' => 'Steve', 'email' => 'email@users.companies', 'phone' => '+123456789982', 'cell_phone' => '+321654987789', 'country_code' => 'EG', 'city' => 'Alexandria', // 'zip_code' => 11865, 'line1' => 'Line1 Details', 'line2' => 'Line2 Details', 'line3' => 'Line3 Details', ], 'shipping_date_time' => time() + 50000, 'due_date' => time() + 60000, 'comments' => 'No Comment', 'pickup_location' => 'at reception', 'pickup_guid' => $guid, //from createPickup function 'weight' => 123, // KG 'number_of_pieces' => 1, 'product_group' => 'EXP', 'product_type' => 'PDX', // if u don't pass it, it will take the config default value 'height' => 5.5, // CM 'width' => 3, // CM 'length' => 2.3, // CM 'description' => 'Goods Description, like Boxes of flowers', // 'goods_origin_country' => 'EG', // 'cash_on_delivery_amount' => array( // 'value' => 1, // 'currency_code' => 'USD' // ), // 'insurance_amount' => array( // 'value' => 0, // 'currencyCode' => '' // ), // 'CollectAmount' => array( // 'Value' => 0, // 'CurrencyCode' => '' // ), // 'cash_additional_amount' => array( // 'Value' => 0, // 'CurrencyCode' => '' // ), // 'cash_additional_amount_description' => '', // 'customs_value_amount' => array( // 'Value' => 0, // 'CurrencyCode' => '' // ), // 'items' => array( // 'package_type' => 'Box', // 'quantity' => 1, // 'weight' => array( // 'Value' => 1, // 'Unit' => 1, // ), // 'comments' => 'Docs', // 'reference' => '' // ) ]); if (!empty($callResponse->error)) { foreach ($callResponse->errors as $errorObject) { handleError($errorObject->Code, $errorObject->Message); } } else { // extract your data here, for example // $shipmentId = $response->Shipments->ProcessedShipment->ID; // $labelUrl = $response->Shipments->ProcessedShipment->ShipmentLabel->LabelURL; }
计算运费
use Aadshalshihry\Aramex\Aramex; $originAddress = [ 'line1' => 'Test string', 'city' => 'Amman', 'country_code' => 'JO' ]; $destinationAddress = [ 'line1' => 'Test String', 'city' => 'Dubai', 'country_code' => 'AE' ]; $shipmentDetails = [ 'weight' => 5, // KG 'number_of_pieces' => 2, 'payment_type' => 'P', // if u don't pass it, it will take the config default value 'product_group' => 'EXP', // if u don't pass it, it will take the config default value 'product_type' => 'PPX', // if u don't pass it, it will take the config default value 'height' => 5.5, // CM 'width' => 3, // CM 'length' => 2.3 // CM ]; $shipmentDetails = [ 'weight' => 5, // KG 'number_of_pieces' => 2, ]; $currency = 'USD'; $data = Aramex::calculateRate($originAddress, $destinationAddress , $shipmentDetails , 'USD'); if(!$data->error){ } else{ // handle $data->errors }
跟踪货运
use Aadshalshihry\Aramex\Aramex; //find createShipmentResults , anotherCreateShipmentResults from 'createShipment' function $shipments = [ $createShipmentResults->Shipments->ProcessedShipment->ID, $anotherCreateShipmentResults->Shipments->ProcessedShipment->ID, ]; $data = Aramex::trackShipments($shipments); if (!$data->error){ // Code Here } else { // handle error }
获取国家
use Aadshalshihry\Aramex\Aramex; $data = Aramex::fetchCountries('EG'); //Or $data = Aramex::fetchCountries();
获取城市
use Aadshalshihry\Aramex\Aramex; $data = Aramex::fetchCities('EG');
验证地址
use Aadshalshihry\Aramex\Aramex; $data = Aramex::validateAddress([ 'country_code' => 'EG', 'city' => 'Cairo', 'zip_code' => 11865, 'line1' => 'Line1 Details', 'line2' => 'Line2 Details', 'line3' => 'Line3 Details', ]);
- 注意,此包需要在您的服务器上启用 SOAP 扩展
- 使用实时账户数据,因为测试数据通常不起作用
- 您可以从以下链接获取文档:https://www.aramex.com/docs/default-source/resourses/resourcesdata/shipping-services-api-manual.pdf
- 从https://www.aramex.com/be/en/solutions-services/developers-solutions-center/apis下载 aramex API 源代码
- 此包基于 https://github.com/Moustafa22/Laravel-Aramex-SDK 构建