gdinko / dynamicexpress
Laravel 动态 Express API 包装器
v1.0.4
2022-11-30 14:57 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0
- league/iso3166: ^4.1
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
Laravel DynamicExpress API 包装器
安装
您可以通过 composer 安装此软件包
composer require gdinko/dynamicexpress
如果您计划使用数据库存储品名
php artisan migrate
如果您需要导出配置文件
php artisan vendor:publish --tag=dynamicexpress-config
如果您需要导出迁移文件
php artisan vendor:publish --tag=dynamicexpress-migrations
如果您需要导出模型
php artisan vendor:publish --tag=dynamicexpress-models
如果您需要导出命令
php artisan vendor:publish --tag=dynamicexpress-commands
配置
DYNAMICEXPRESS_API_USER=
DYNAMICEXPRESS_API_PASS=
DYNAMICEXPRESS_API_WSDL= #default = https://system.dynamicexpress.eu/schema.wsdl
用法
运行时设置
DynamicExpress::setAccount('user', 'pass'); DynamicExpress::addAccountToStore('AccountUser', 'AccountPass'); DynamicExpress::getAccountFromStore('AccountUser'); DynamicExpress::setAccountFromStore('AccountUser');
支持多账户。在 AppServiceProvider 的 boot 方法中添加账户
public function boot() { DynamicExpress::addAccountToStore( 'AccountUser', 'AccountPass' ); DynamicExpress::addAccountToStore( 'AccountUser_XXX', 'AccountPass_XXX' ); }
命令
#sync countries with database (use -h to view options) php artisan dynamic-express:sync-countries #sync cities with database (use -h to view options) php artisan dynamic-express:sync-cities #sync offices with database (use -h to view options) php artisan dynamic-express:sync-offices #create cities map with other carriers in database (use -h to view options) php artisan dynamic-express:map-cities #sync all nomenclatures with database (use -h to view options) php artisan dynamic-express:sync-all #get payments (use -h to view options) php artisan dynamic-express:get-payments #get dynamic express api status (use -h to view options) php artisan dynamic-express:api-status #track parcels (use -h to view options) php artisan dynamic-express:track
模型
CarrierDynamicExpressCountry CarrierDynamicExpressCity CarrierDynamicExpressOffice CarrierDynamicExpressPayment CarrierDynamicExpressApiStatus CarrierDynamicExpressTracking
事件
CarrierDynamicExpressTrackingEvent CarrierDynamicExpressPaymentEvent
包裹跟踪
- 订阅跟踪事件,如果您调度了跟踪命令,您将收到最后的跟踪信息
Event::listen(function (CarrierDynamicExpressTrackingEvent $event) { echo $event->account; dd($event->tracking); });
- 在使用跟踪命令之前,您需要创建自己的命令并定义 setUp 方法
php artisan make:command TrackCarrierDynamicExpress
- 在 app/Console/Commands/TrackCarrierDynamicExpress 中定义您的逻辑,以跟踪包裹
use Gdinko\DynamicExpress\Commands\TrackCarrierDynamicExpressBase; class TrackCarrierDynamicExpressSetup extends TrackCarrierDynamicExpressBase { protected function setup() { //define parcel selection logic here // $this->parcels = []; } }
- 使用命令
php artisan dynamic-express:track
示例
计算价格
$data = [ // value is taken with getServices Method. Here 1 is -> // -> "Бързи градски услуги" (fast urban services) 'service' => 1, // value is taken with getSubServices Method. -> // -> Here 18 is "48 часа икономична" (48h economical) 'subservice' => 18, // 0(zero) or 1 (1 if there will be fixed delivery, 0 if not) 'fix_chas' => 0, // 0(zero) or 1 (1 if there will be return reciept, 0 if not) 'return_receipt' => 0, // 0(zero) or 1 (1 if there will be return document, 0 if not) 'return_doc' => 0, // COD(cash on delivery). 0(zero) if there is no COD. -> // -> USE "."(dot) for decimals! 'nal_platej' => 50, // Insurance Value. 0(zero) if there is no insurance. -> // -> USE "."(dot) for decimals! 'zastrahovka' => 50, // Weigth in kg. CAN'T be 0(zero). Use "."(dot) for decimals. 'teglo' => 2.5, // ID of the country(ISO standart). -> // -> Required only for international delivery 'country_b' => 100, ]; $priceData = DynamicExpress::calculate($data); dd($priceData);
您可以使用 WDSL Schema 中的所有方法,如下所示
DynamicExpress::getMyObjectInfo(); DynamicExpress::getMyObjects(); DynamicExpress::getOfficesCity(); DynamicExpress::getOfficesCord(100); DynamicExpress::getSoapCouriers(); //and so on , see the documentation
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 了解详细信息。
安全
如果您发现任何安全问题,请通过电子邮件 dinko359@gmail.com 而不是使用问题跟踪器来报告。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。