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文檔中可以使用不同測試案例的模擬響應的測試註冊號。