zebrainsteam / avtocod-b2b-api-php
用于操作B2B API服务的PHP包
v4.2.0
2021-04-05 05:52 UTC
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6.0 || ~7.0
- ocramius/package-versions: ^1.2
Requires (Dev)
- avto-dev/guzzle-url-mock: ^1.5
- fzaninotto/faker: ^1.9.1
- mockery/mockery: ^1.3
- phpstan/phpstan: ~0.12
- phpunit/phpunit: ^8.5.4
- vlucas/phpdotenv: ^3.4 || ^4.0 || ^5.0
Suggests
- avtocod/specs: Avtocod project public specifications.
This package is not auto-updated.
Last update: 2024-09-25 22:31:42 UTC
README
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');
例如,如果您想为A111AA177
(GRZ
类型)生成报告,您可以
<?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
变更日志
变更日志可以在此处找到。
支持
如果您发现任何包错误,请在当前存储库中创建一个问题。
许可证
这是一个开源软件,根据MIT许可证授权。