art4/wegliphant

weg.li API 的 PHP 客户端

0.3.0 2024-03-07 12:54 UTC

This package is auto-updated.

Last update: 2024-09-22 14:08:26 UTC


README

Latest Version Software License Build Status codecov Total Downloads

🐘 Wegliphant 是一个针对 weg.li 🚲💨 API 的 PHP 客户端。

要求:PHP ^8.1

使用方法

安装

您可以使用 Composer 安装 Wegliphant。

composer require art4/wegliphant

不要忘记使用 require 'vendor/autoload.php'; 加载自动加载器。

配置

Wegliphant 需要 PSR-18 HTTP 客户端PSR-17 请求工厂 实现。

此示例使用 Guzzle

$client = \Art4\Wegliphant\Client::create(
    new \GuzzleHttp\Client(),
    new \GuzzleHttp\Psr7\HttpFactory(),
);

可选,您可以使用 authenticate() 设置 API 密钥。weg.li API 几乎所有区域都需要 API 密钥。没有 API 密钥,所有请求都将无授权发送。您可以在 此处 找到您的 API 密钥。

$client->authenticate($apiKey);

列出所有自己的通知

$notices = $client->listOwnNotices();

// $notices contains:
[
    [...],
    [
        'token' => '8843d7f92416211de9ebb963ff4ce281',
        'status' => 'shared',
        'street' => 'Musterstraße 123',
        'city' => 'Berlin',
        'zip' => '12305',
        'latitude' => 52.5170365,
        'longitude' => 13.3888599,
        'registration' => 'EX AM 713',
        'color' => 'white',
        'brand' => 'Car brand',
        'charge' => [
            'tbnr' => '141312',
            'description' => 'Sie parkten im absoluten Haltverbot (Zeichen 283).',
            'fine' => '25.0',
            'bkat' => '§ 41 Abs. 1 iVm Anlage 2, § 49 StVO; § 24 Abs. 1, 3 Nr. 5 StVG; 52 BKat',
            'penalty' => null,
            'fap' => null,
            'points' => 0,
            'valid_from' => '2021-11-09T00:00:00.000+01:00',
            'valid_to' => null,
            'implementation' => null,
            'classification' => 5,
            'variant_table_id' => 741017,
            'rule_id' => 39,
            'table_id' => null,
            'required_refinements' => '00000000000000000000000000000000',
            'number_required_refinements' => 0,
            'max_fine' => '0.0',
            'created_at' => '2023-09-18T15:30:43.312+02:00',
            'updated_at' => '2023-09-18T15:30:43.312+02:00',
        ],
        'tbnr' => '141312',
        'start_date' => '2023-11-12T11:31:00.000+01:00',
        'end_date' => '2023-11-12T11:36:00.000+01:00',
        'note' => 'Some user notes',
        'photos' => [
            [
                'filename' => 'IMG_20231124_113156.jpg',
                'url' => 'https://example.com/storage/IMG_20231124_113156.jpg',
            ],
        ],
        'created_at' => '2023-11-12T11:33:29.423+01:00',
        'updated_at' => '2023-11-12T11:49:24.383+01:00',
        'sent_at' => '2023-11-12T11:49:24.378+01:00',
        'vehicle_empty' => true,
        'hazard_lights' => false,
        'expired_tuv' => false,
        'expired_eco' => false,
        'over_2_8_tons' => false,
    ],
    [...],
],

通过令牌获取一个通知

$notice = $client->getNoticeByToken('8843d7f92416211de9ebb963ff4ce281');

// $notice contains:
[
    'token' => '8843d7f92416211de9ebb963ff4ce281',
    'status' => 'shared',
    'street' => 'Musterstraße 123',
    'city' => 'Berlin',
    'zip' => '12305',
    'latitude' => 52.5170365,
    'longitude' => 13.3888599,
    'registration' => 'EX AM 713',
    'color' => 'white',
    'brand' => 'Car brand',
    'charge' => [
        'tbnr' => '141312',
        'description' => 'Sie parkten im absoluten Haltverbot (Zeichen 283).',
        'fine' => '25.0',
        'bkat' => '§ 41 Abs. 1 iVm Anlage 2, § 49 StVO; § 24 Abs. 1, 3 Nr. 5 StVG; 52 BKat',
        'penalty' => null,
        'fap' => null,
        'points' => 0,
        'valid_from' => '2021-11-09T00:00:00.000+01:00',
        'valid_to' => null,
        'implementation' => null,
        'classification' => 5,
        'variant_table_id' => 741017,
        'rule_id' => 39,
        'table_id' => null,
        'required_refinements' => '00000000000000000000000000000000',
        'number_required_refinements' => 0,
        'max_fine' => '0.0',
        'created_at' => '2023-09-18T15:30:43.312+02:00',
        'updated_at' => '2023-09-18T15:30:43.312+02:00',
    ],
    'tbnr' => '141312',
    'start_date' => '2023-11-12T11:31:00.000+01:00',
    'end_date' => '2023-11-12T11:36:00.000+01:00',
    'note' => 'Some user notes',
    'photos' => [
        [
            'filename' => 'IMG_20231124_113156.jpg',
            'url' => 'https://example.com/storage/IMG_20231124_113156.jpg',
        ],
    ],
    'created_at' => '2023-11-12T11:33:29.423+01:00',
    'updated_at' => '2023-11-12T11:49:24.383+01:00',
    'sent_at' => '2023-11-12T11:49:24.378+01:00',
    'vehicle_empty' => true,
    'hazard_lights' => false,
    'expired_tuv' => false,
    'expired_eco' => false,
    'over_2_8_tons' => false,
],

列出所有区域

$districts = $client->listDistricts();

// $districts contains:
[
    [...],
    [
        'name' => 'Berlin',
        'zip' => '12305',
        'email' => 'mail@example.com',
        'prefixes' => [
            'B',
        ],
        'latitude' => 52.5170365,
        'longitude' => 13.3888599,
        'aliases' => null,
        'personal_email' => false,
        'created_at' => '2019-09-24T14:56:35.624+02:00',
        'updated_at' => '2020-03-06T17:53:09.034+01:00',
    ],
    [...],
],

通过邮编获取一个区域

$district = $client->getDistrictByZip('12305');

// $district contains:
[
    'name' => 'Berlin',
    'zip' => '12305',
    'email' => 'mail@example.com',
    'prefixes' => [
        'B',
    ],
    'latitude' => 52.5170365,
    'longitude' => 13.3888599,
    'aliases' => null,
    'personal_email' => false,
    'created_at' => '2019-09-24T14:56:35.624+02:00',
    'updated_at' => '2020-03-06T17:53:09.034+01:00',
],

列出所有费用

$charges = $client->listCharges();

// $charges contains:
[
    [...],
    [
        'tbnr' => '141313',
        'description' => 'Sie parkten im absoluten Haltverbot (Zeichen 283) und behinderten +) dadurch Andere.',
        'fine' => '40.0',
        'bkat' => '§ 41 Abs. 1 iVm Anlage 2, § 1 Abs. 2, § 49 StVO; § 24 Abs. 1, 3 Nr. 5 StVG; 52.1 BKat; § 19 OWiG',
        'penalty' => null,
        'fap' => null,
        'points' => 0,
        'valid_from' => '2021-11-09T00:00:00.000+01:00',
        'valid_to' => null,
        'implementation' => 2,
        'classification' => 5,
        'variant_table_id' => 741017,
        'rule_id' => 39,
        'table_id' => null,
        'required_refinements' => '00000000000000000000000000000000',
        'number_required_refinements' => 1,
        'max_fine' => '0.0',
        'created_at' => '2023-09-18T15:30:43.329+02:00',
        'updated_at' => '2023-09-18T15:30:43.329+02:00',
    ],
    [...],
],

通过 tbnr 列出一个费用

$charge = $client->getChargeByTbnr('141313');

// $charge contains:
[
    'tbnr' => '141313',
    'description' => 'Sie parkten im absoluten Haltverbot (Zeichen 283) und behinderten +) dadurch Andere.',
    'fine' => '40.0',
    'bkat' => '§ 41 Abs. 1 iVm Anlage 2, § 1 Abs. 2, § 49 StVO; § 24 Abs. 1, 3 Nr. 5 StVG; 52.1 BKat; § 19 OWiG',
    'penalty' => null,
    'fap' => null,
    'points' => 0,
    'valid_from' => '2021-11-09T00:00:00.000+01:00',
    'valid_to' => null,
    'implementation' => 2,
    'classification' => 5,
    'variant_table_id' => 741017,
    'rule_id' => 39,
    'table_id' => null,
    'required_refinements' => '00000000000000000000000000000000',
    'number_required_refinements' => 1,
    'max_fine' => '0.0',
    'created_at' => '2023-09-18T15:30:43.329+02:00',
    'updated_at' => '2023-09-18T15:30:43.329+02:00',
],

开发

您可以使用 Docker 创建完整开发环境。

docker compose build
docker compose up -d
docker compose exec php php --version

它看起来像这样

$ docker compose exec php php --version
PHP 8.3.3 (cli) (built: Feb 16 2024 21:02:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.3, Copyright (c), by Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans

测试

我们使用 PHPUnitPHPStanPHP-CS-Fixer 进行测试、静态代码分析和强制执行代码样式 PER-CS2.0。您可以使用 composer 脚本 test 运行所有检查。

docker compose exec php composer test

您还可以使用 composer 脚本 phpstanphpunitcodestyle 运行一个特定检查。

docker compose exec php composer phpstan
docker compose exec php composer phpunit
docker compose exec php composer codestyle