gdinko/dynamicexpress

Laravel 动态 Express API 包装器

v1.0.4 2022-11-30 14:57 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:43 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel DynamicExpress API 包装器

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

包裹跟踪

  1. 订阅跟踪事件,如果您调度了跟踪命令,您将收到最后的跟踪信息
Event::listen(function (CarrierDynamicExpressTrackingEvent $event) {
    echo $event->account;
    dd($event->tracking);
});
  1. 在使用跟踪命令之前,您需要创建自己的命令并定义 setUp 方法
php artisan make:command TrackCarrierDynamicExpress
  1. 在 app/Console/Commands/TrackCarrierDynamicExpress 中定义您的逻辑,以跟踪包裹
use Gdinko\DynamicExpress\Commands\TrackCarrierDynamicExpressBase;

class TrackCarrierDynamicExpressSetup extends TrackCarrierDynamicExpressBase
{
    protected function setup()
    {
        //define parcel selection logic here
        // $this->parcels = [];
    }
}
  1. 使用命令
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)。请参阅 许可证文件 了解更多信息。