zebrainsteam/avtocod-b2b-api-php

用于操作B2B API服务的PHP包

v4.2.0 2021-04-05 05:52 UTC

README

logo

B2B API服务的PHP客户端

原始库的版本 https://github.com/avtocod/b2b-api-php,具有与php 7.1版本兼容的能力,并更新了依赖项

安装

使用以下命令使用composer安装此包

$ composer require avtocod/b2b-api-php "^3.2"

需要安装composer如何安装composer)。

您需要修复包的主版本号。

用法

在开始使用此包之前,您必须具备以下条件

  • 服务用户登录
  • 用户密码
  • 用户域名
  • 以及报告类型名称

要获取这些值,请联系我们的B2B销售经理(b2b@avtocod.ru

现在,让我们创建B2B API客户端实例

<?php

use Avtocod\B2BApi\Client;
use Avtocod\B2BApi\Settings;
use Avtocod\B2BApi\Tokens\Auth\AuthToken;

$client = new Client(new Settings(AuthToken::generate('username', 'password', 'domain')));

然后我们可以进行以下操作 (每个调用都将返回一个包含服务器响应数据的对象)

<?php /** @var \Avtocod\B2BApi\Client $client */

// Test connection
$client->devPing();

// Debug token generation
$client->devToken('username', 'password');

// Retrieve information about current user
$client->user(true);

// Retrieve balance information for report type
$client->userBalance('report_type_uid@domain');

// Retrieve report types data
$client->userReportTypes();

// Get reports list
$client->userReports();

// Get report by unique report ID
$client->userReport('report_uid_SOMEIDENTIFIERGOESHERE@domain');

// Make (generate) report
$client->userReportMake('report_type_uid@domain', 'VIN', 'Z94CB41AAGR323020');

// Refresh existing report
$client->userReportRefresh('report_uid_SOMEIDENTIFIERGOESHERE@domain');

例如,如果您想为A111AA177GRZ类型)生成报告,您可以

<?php /** @var \Avtocod\B2BApi\Client $client */

// Make report (this operation is asynchronous)
$report_uid = $client
    ->userReportMake($this->report_type, 'GRZ', 'A111AA177', null, true)
    ->first()
    ->getReportUid();

// Wait for report is ready
while (true) {
    if ($client->userReport($report_uid, false)->first()->isCompleted()) {
        break;
    }
    
    \sleep(1);
}

$content = $client->userReport($report_uid)->first()->getContent();

$vin_code  = $content->getByPath('identifiers.vehicle.vin');   // (string) 'JTMHX05J704083922'
$engine_kw = $content->getByPath('tech_data.engine.power.kw'); // (int) 227

测试

对于包的测试,我们使用phpunit框架和docker-ce + docker-compose作为开发环境。因此,在克隆存储库后,只需在终端中写入

$ make build
$ make latest # or 'make lowest'
$ make test

变更日志

Release date Commits since latest release

变更日志可以在此处找到

支持

Issues Issues

如果您发现任何包错误,请在当前存储库中创建一个问题

许可证

这是一个开源软件,根据MIT许可证授权。