aboodma / aramex-integration
与阿联酋速递服务集成(跟踪/运输/运费计算器)
1.0.1
2024-08-07 09:52 UTC
Requires
- guzzlehttp/guzzle: ^7.8
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-13 05:32:56 UTC
README
此PHP库允许轻松集成阿联酋速递API。它提供一组模型和客户端,用于与API交互以创建运输、生成标签等。
要求
- PHP 8或更高版本
- Composer
安装
使用Composer安装库
composer require aboodma/aramex-integration
用法
配置
使用您的阿联酋速递账户详细信息创建配置对象
use Aboodma\AramexIntegration\Config; $config = (new Config()) ->setUsername("your_username") ->setPassword("your_password") ->setVersion("v1.0") ->setAccountNumber("your_account_number") ->setAccountPin("your_account_pin") ->setAccountEntity("your_account_entity") ->setAccountCountryCode("your_account_country_code") ->setSource(24);
创建运输
use Aboodma\AramexIntegration\Models\Address; use Aboodma\AramexIntegration\Models\Contact; use Aboodma\AramexIntegration\Models\Party; use Aboodma\AramexIntegration\Models\Dimensions; use Aboodma\AramexIntegration\Models\Weight; use Aboodma\AramexIntegration\Models\Amount; use Aboodma\AramexIntegration\Models\ShipmentDetails; use Aboodma\AramexIntegration\Models\Shipment; use Aboodma\AramexIntegration\Models\LabelInfo; use Aboodma\AramexIntegration\Models\ClientInfo; use Aboodma\AramexIntegration\AramexClient; use Aboodma\AramexIntegration\Exceptions\AramexException; // Shipper details $shipperAddress = (new Address()) ->setLine1("Test Shipper Address Line1") ->setLine2("Test Shipper Address Line2") ->setCity("Dubai") ->setPostCode("000000") ->setCountryCode("AE"); $shipperContact = (new Contact()) ->setPersonName("Test Shipper Name") ->setCompanyName("Test Shipper Company Name") ->setPhoneNumber1("048707766") ->setCellPhone("971556893100") ->setEmailAddress("test@aramex.com"); $shipper = (new Party()) ->setReference1("Shipper Reference") ->setAccountNumber("45796") ->setPartyAddress($shipperAddress) ->setContact($shipperContact); // Consignee details $consigneeAddress = (new Address()) ->setLine1("Test Consignee Address Line1") ->setLine2("Test Consignee Address Line2") ->setLine3("Test Consignee Address Line3") ->setCity("Dubai") ->setStateOrProvinceCode("FU") ->setCountryCode("AE"); $consigneeContact = (new Contact()) ->setPersonName("Test Consignee Name") ->setCompanyName("Test Consignee Company Name") ->setPhoneNumber1("048707766") ->setCellPhone("971556893100") ->setEmailAddress("tets@hotmail.com"); $consignee = (new Party()) ->setAccountNumber("0") ->setPartyAddress($consigneeAddress) ->setContact($consigneeContact); // Shipment details $dimensions = (new Dimensions()) ->setLength(0) ->setWidth(0) ->setHeight(0) ->setUnit("CM"); $actualWeight = (new Weight()) ->setUnit("KG") ->setValue(0.1); $chargeableWeight = (new Weight()) ->setUnit("KG") ->setValue(0); $amount = (new Amount()) ->setCurrencyCode("AED") ->setValue(10); $details = (new ShipmentDetails()) ->setDimensions($dimensions) ->setActualWeight($actualWeight) ->setChargeableWeight($chargeableWeight) ->setDescriptionOfGoods("Items") ->setGoodsOriginCountry("AE") ->setNumberOfPieces(1) ->setProductGroup("DOM") ->setProductType("ONP") ->setPaymentType("P") ->setPaymentOptions("ACCT") ->setCustomsValueAmount($amount); $shipment = (new Shipment()) ->setShipper($shipper) ->setConsignee($consignee) ->setDetails($details) ->setReference1("Shipment Reference"); // Label info $labelInfo = (new LabelInfo()) ->setReportID(9729) ->setReportType("URL"); // Client info $clientInfo = (new ClientInfo()) ->setUserName("testingapi@aramex.com") ->setPassword('R123456789$r') ->setVersion("v1.0") ->setAccountNumber("45796") ->setAccountPin("116216") ->setAccountEntity("DXB") ->setAccountCountryCode("AE") ->setSource(24); // Initialize AramexClient and make the request $client = new AramexClient($config); try { $response = $client->createShipment($shipment, $labelInfo, $clientInfo); echo json_encode($response, JSON_PRETTY_PRINT); } catch (AramexException $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; echo 'HTTP Status Code: ' . $e->getHttpStatusCode() . PHP_EOL; echo 'Error Details: ' . print_r($e->getErrorDetails(), true); }
模型
地址
表示一个地址。
setLine1(string $line1): self
setLine2(string $line2): self
setLine3(string $line3): self
setCity(string $city): self
setStateOrProvinceCode(string $stateOrProvinceCode): self
setPostCode(string $postCode): self
setCountryCode(string $countryCode): self
联系人
表示一个联系人。
setPersonName(string $personName): self
setCompanyName(string $companyName): self
setPhoneNumber1(string $phoneNumber1): self
setPhoneNumber1Ext(string $phoneNumber1Ext): self
setPhoneNumber2(string $phoneNumber2): self
setPhoneNumber2Ext(string $phoneNumber2Ext): self
setFaxNumber(string $faxNumber): self
setCellPhone(string $cellPhone): self
setEmailAddress(string $emailAddress): self
setType(string $type): self
当事人
表示参与运输的当事人(发货人或收货人)。
setReference1(string $reference1): self
setReference2(string $reference2): self
setAccountNumber(string $accountNumber): self
setPartyAddress(Address $partyAddress): self
setContact(Contact $contact): self
尺寸
表示运输的尺寸。
setLength(float $length): self
setWidth(float $width): self
setHeight(float $height): self
setUnit(string $unit): self
重量
表示运输的重量。
setUnit(string $unit): self
setValue(float $value): self
金额
表示货币金额。
setCurrencyCode(string $currencyCode): self
setValue(float $value): self
运输详情
表示运输的详细信息。
setDimensions(Dimensions $dimensions): self
setActualWeight(Weight $actualWeight): self
setChargeableWeight(Weight $chargeableWeight): self
setDescriptionOfGoods(string $descriptionOfGoods): self
setGoodsOriginCountry(string $goodsOriginCountry): self
setNumberOfPieces(int $numberOfPieces): self
setProductGroup(string $productGroup): self
setProductType(string $productType): self
setPaymentType(string $paymentType): self
setPaymentOptions(string $paymentOptions): self
setCustomsValueAmount(Amount $customsValueAmount): self
setCashOnDeliveryAmount(Amount $cashOnDeliveryAmount): self
setInsuranceAmount(Amount $insuranceAmount): self
setCashAdditionalAmount(Amount $cashAdditionalAmount): self
setCashAdditionalAmountDescription(string $cashAdditionalAmountDescription): self
setCollectAmount(Amount $collectAmount): self
setServices(string $services): self
setItems(array $items): self
setDeliveryInstructions(string $deliveryInstructions): self
setAdditionalProperties(string $additionalProperties): self
setContainsDangerousGoods(bool $containsDangerousGoods): self
运输
表示运输。
setReference1(string $reference1): self
setReference2(string $reference2): self
setReference3(string $reference3): self
setShipper(Party $shipper): self
setConsignee(Party $consignee): self
setThirdParty(Party $thirdParty): self
setShippingDateTime(\DateTime $shippingDateTime): self
setDueDate(\DateTime $dueDate): self
setComments(string $comments): self
setPickupLocation(string $pickupLocation): self
setOperationsInstructions(string $operationsInstructions): self
setAccountingInstructions(string $accountingInstructions): self
setDetails(ShipmentDetails $details): self
setAttachments(array $attachments): self
setForeignHAWB(string $foreignHAWB): self
setTransportType(string $transportType): self
setPickupGUID(string $pickupGUID): self
setNumber(string $number): self
setScheduledDelivery(\DateTime $scheduledDelivery): self
标签信息
表示货物运输的标签信息。
setReportID(int $reportID): self
setReportType(string $reportType): self
ClientInfo
表示客户信息。
setUserName(string $userName): self
setPassword(string $password): self
setVersion(string $version): self
setAccountNumber(string $accountNumber): self
setAccountPin(string $accountPin): self
setAccountEntity(string $accountEntity): self
setAccountCountryCode(string $accountCountryCode): self
setSource(int $source): self
错误处理
如果API请求失败,将抛出AramexException异常。该异常包含API返回的错误信息、HTTP状态码和错误详情。
try { $response = $client->createShipment($shipment, $labelInfo, $clientInfo); echo json_encode($response, JSON_PRETTY_PRINT); } catch (AramexException $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; echo 'HTTP Status Code: ' . $e->getHttpStatusCode() . PHP_EOL; echo 'Error Details: ' . print_r($e->getErrorDetails(), true); }
日志记录
该库将请求负载、响应负载和错误响应记录到日志文件中,用于调试目的。
贡献
请在GitHub仓库提交问题和拉取请求。
许可证
本项目采用MIT许可证。