gdinko / econt
Laravel Econt API Wrapper
v1.0.16
2024-08-06 16:29 UTC
Requires
- php: ^7.4|^8.0|^8.1|^8.2|^8.3
- guzzlehttp/guzzle: ^7.4
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- nunomaduro/collision: ^5.11
- nunomaduro/larastan: ^1.0
- orchestra/testbench: ^6.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.2
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.1
- phpunit/phpunit: ^9.0
README
安装
您可以通过composer安装此包
composer require gdinko/econt
如果您计划使用数据库存储品名
php artisan migrate
如果您需要导出配置文件
php artisan vendor:publish --tag=econt-config
如果您需要导出迁移文件
php artisan vendor:publish --tag=econt-migrations
如果您需要导出模型
php artisan vendor:publish --tag=econt-models
如果您需要导出命令
php artisan vendor:publish --tag=econt-commands
配置
ECONT_ENV=test|production #default=test ECONT_API_USER= #default=iasp-dev ECONT_API_PASS= #default=iasp-dev ECONT_API_TEST_BASE_URI= #default=https://demo.econt.com/ee/services ECONT_API_PRODUCTION_BASE_URI= #default=https://ee.econt.com/services ECONT_API_TIMEOUT= #default=5
用法
运行时设置
Econt::setAccount('user', 'pass'); Econt::setBaseUrl('endpoint'); Econt::setTimeout(99); Econt::addAccountToStore('AccountUser', 'AccountPass'); Econt::getAccountFromStore('AccountUser'); Econt::setAccountFromStore('AccountUser');
在 AppServiceProvider 中通过 boot 方法添加多个账户以支持多个账户
public function boot() { Econt::addAccountToStore( 'AccountUser', 'AccountPass' ); Econt::addAccountToStore( 'AccountUser_XXX', 'AccountPass_XXX' ); }
方法
//Nomenclatures Econt::getCountries(); Econt::getCities(); Econt::getOffices(); Econt::getStreets(); Econt::getQuarters(); //Labels Econt::createLabel(); Econt::createLabels(); Econt::updateLabel(); Econt::deleteLabels(); //Misc Econt::requestCourier(); Econt::getRequestCourierStatus(); Econt::getShipmentStatuses(); Econt::getClientProfiles(); Econt::paymentReport();
命令
#sync countries with database (use -h to view options) php artisan econt:sync-countries #sync cities with database (use -h to view options) php artisan econt:sync-cities #create cities map with other carriers in database (use -h to view options) php artisan econt:map-cities #sync offices with database (use -h to view options) php artisan econt:sync-offices #sync querters with database (use -h to view options) php artisan econt:sync-quarters #sync stretts with database (use -h to view options) php artisan econt:sync-streets #sync all nomenclatures with database (use -h to view options) php artisan econt:sync-all #get payments (use -h to view options) php artisan econt:get-payments #get econt api status (use -h to view options) php artisan econt:api-status #track parcels (use -h to view options) php artisan econt:track
模型
CarrierEcontCountry CarrierEcontCity CarrierEcontOffice CarrierEcontStreet CarrierEcontQuarter CarrierEcontPayment CarrierEcontApiStatus CarrierEcontTracking CarrierCityMap
事件
CarrierEcontTrackingEvent CarrierEcontPaymentEvent
包裹跟踪
- 订阅跟踪事件,如果跟踪命令已安排,您将收到最新的跟踪信息
Event::listen(function (CarrierEcontTrackingEvent $event) { echo $event->account; dd($event->tracking); });
- 在使用跟踪命令之前,您需要创建自己的命令并定义 setUp 方法
php artisan make:command TrackCarrierEcont
- 在 app/Console/Commands/TrackCarrierEcont 中定义要跟踪的包裹的逻辑
use Gdinko\Econt\Commands\TrackCarrierEcontBase; class TrackCarrierEcontSetup extends TrackCarrierEcontBase { protected function setup() { //define parcel selection logic here // $this->parcels = []; } }
- 使用命令
php artisan econt:track
示例
地址验证
try { $address = new Address([ 'city' => [ 'name' => 'София' ], 'street' => 'България', 'num' => '100' ]); dd(Econt::validateAddress($address)); } catch (EcontValidationException $eve) { echo $eve->getMessage(); echo $eve->getCode(); print_r($eve->getErrors()); } catch (EcontException $ee) { echo $ee->getMessage(); echo $ee->getCode(); print_r($ee->getErrors()); }
获取地址附近的办公室
try { $address = new Address([ 'city' => [ 'name' => 'София' ], 'street' => 'България', 'num' => '100' ]); dd(Econt::getNearestOffices($address)); } catch (EcontValidationException $eve) { echo $eve->getMessage(); echo $eve->getCode(); print_r($eve->getErrors()); } catch (EcontException $ee) { echo $ee->getMessage(); echo $ee->getCode(); print_r($ee->getErrors()); }
计算价格
$labelData = [ 'senderClient' => [ 'name' => 'Иван Иванов', 'phones' => [ 0 => '0888888888', ], ], 'senderAddress' => [ 'city' => [ 'country' => [ 'code3' => 'BGR', ], 'name' => 'София', 'postCode' => 1000, ], ], 'senderOfficeCode' => '1127', 'receiverAddress' => [ 'city' => [ 'country' => [ 'code3' => 'BGR', ], 'name' => 'София', 'postCode' => 1000, ], 'street' => 'България', 'num' => '100', ], 'packCount' => 1, 'shipmentType' => ShipmentType::PACK, 'weight' => 3.4, 'shipmentDescription' => 'обувки', 'services' => [ 'cdAmount' => 122.59, 'cdType' => 'get', 'cdCurrency' => 'BGN', 'smsNotification' => true, ], 'payAfterAccept' => false, 'payAfterTest' => false, ]; $label = new Label( $labelData, LabelMode::CALCULATE ); $result = Econt::createLabel($label);
创建标签
$labelData = [ 'senderClient' => [ 'name' => 'Иван Иванов', 'phones' => [ 0 => '0888888888', ], ], 'senderAddress' => [ 'city' => [ 'country' => [ 'code3' => 'BGR', ], 'name' => 'София', 'postCode' => 1000, ], ], 'senderOfficeCode' => '1127', 'receiverClient' => [ 'name' => 'Димитър Димитров', 'phones' => [ 0 => '0876543210', ], ], 'receiverAddress' => [ 'city' => [ 'country' => [ 'code3' => 'BGR', ], 'name' => 'София', 'postCode' => '1000', ], 'street' => 'България', 'num' => 100, ], 'packCount' => 1, 'shipmentType' => ShipmentType::PACK, 'weight' => 3.4, 'shipmentDescription' => 'обувки', 'services' => [ 'cdAmount' => '122.59', 'cdType' => 'get', 'cdCurrency' => 'BGN', 'smsNotification' => true, ], 'payAfterAccept' => false, 'payAfterTest' => false, 'holidayDeliveryDay' => 'workday', ]; $label = new Label( $labelData, LabelMode::CREATE ); $result = Econt::createLabel($label);
请求快递
try { $curierRequest = [ 'requestTimeFrom' => '2022-05-05 16:00:00', 'requestTimeTo' => '2022-05-05 17:00:00', 'shipmentType' => 'PACK', 'shipmentPackCount' => '1', 'shipmentWeight' => '2', 'senderClient' => [ 'name' => 'Иван Иванов', 'phones' => [ 0 => '0888888888', ], ], 'senderAddress' => [ 'city' => [ 'country' => [ 'code3' => 'BGR', ], 'postCode' => '7012', 'name' => 'Русе', ], 'fullAddress' => 'Алея Младост 7', ], ]; dd( Econt::requestCourier( new Courier($curierRequest) ) ); } catch (EcontValidationException $eve) { echo $eve->getMessage(); echo $eve->getCode(); print_r($eve->getErrors()); } catch (EcontException $ee) { echo $ee->getMessage(); echo $ee->getCode(); print_r($ee->getErrors()); }
获取支付信息
try { dd( Econt::paymentReport(new Payment([ 'dateFrom' => '2022-05-01', 'dateTo' => '2022-05-05' ])) ); } catch (EcontValidationException $eve) { echo $eve->getMessage(); echo $eve->getCode(); print_r($eve->getErrors()); } catch (EcontException $ee) { echo $ee->getMessage(); echo $ee->getCode(); print_r($ee->getErrors()); }
测试
composer test
变更日志
请查看 CHANGELOG 了解最近有哪些变更。
贡献
请查看 CONTRIBUTING 了解详细信息。
安全性
如果您发现任何安全问题,请通过电子邮件 dinko359@gmail.com 反馈,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请查看 许可证文件 了解更多信息。