DVLA车辆查询API V1的PHP客户实施。此软件包提供:
您可以通过作曲家安装库。
composer require lendable/dvla-vehicle-enquiry-api-client
客户端类实现DVLA的REST API,并可以返回可用于请求车辆详细信息的车辆范围。
为了实例化客户端类,我们需要注入添加API密钥身份验证的装饰器和PSR-18兼容层。另外,我们需要定义API的基本URI,以便在UAT和实时服务之间切换。
API的规范包含UAT和LIVE URL。给定的URI不应以斜线( /
)结束,并且也应包含/v1
路径。
例如: https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1
://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1
客户端在任何PSR-7 URIInterface实现中接受URI。
ApikeyauthhttpClientDecorator将所需的API令牌身份验证标头添加到请求中。 Apikey值对象将令牌秘密保留,避免意外暴露。
使用PSR18ClientDecorator,您可以使用任何支持PSR-18标准的HTTP客户端来执行预构建的HTTP请求。
如果您喜欢使用不支持PSR-18标准的HTTP客户端,则可以使用PSR-18请求Interlesterface格式访问请求数据来调用HTTP客户端的简单装饰器,并将HTTP客户端的响应转换为PSR-- 18响应接口格式响应。
例如,在我们的集成测试中,我们使用guzzleclient与使用此PSR-18转换的装饰器。
<?php
declare (strict_types= 1 );
use Lendable Dvla VehicleEnquiry Auth ApiKeyAuthHttpClientDecorator ;
use Lendable Dvla VehicleEnquiry Auth ValueObject ApiKey ;
use Lendable Dvla VehicleEnquiry Client ;
use Lendable Dvla VehicleEnquiry Psr18ClientDecorator ;
use Lendable Dvla VehicleEnquiry Scope VehiclesScope Request EnquiryRequest ;
use Lendable Dvla VehicleEnquiry Scope VehiclesScope ValueObject RegistrationNumber ;
use Nyholm Psr7 Uri ;
$ client = new Client (
new ApiKeyAuthHttpClientDecorator (
new Psr18ClientDecorator (
new YourPsr18HttpClient ()
),
ApiKey :: fromString ( ' YOUR-AUTHENTICATION-TOKEN ' )
),
new Uri ( ' https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1 ' )
);
$ vehicleDetails = $ client -> vehicles ()-> enquireDetails (
EnquiryRequest :: with ( RegistrationNumber :: fromString ( ' AA19PPP ' ))
);
这使AA19PPP
注册号提供了API请求,并且$vehicleDetails
变量将包含一个InquiryResponse对象,其中包含值中的所有返回的API响应数据。
此示例是使用UAT API URL和一个测试注册号。 DVLA车辆查询服务API文档中可以使用不同测试案例的模拟响应的测试注册号。