madmatt/id3global-service

允许PHP驱动的网站与GBG ID3global API通信以验证身份。此库与GBG PLC没有任何关联。

1.1.0 2021-11-26 12:03 UTC

This package is auto-updated.

Last update: 2024-08-26 18:04:14 UTC


README

允许PHP驱动的网站通过GBG ID3global API验证身份。

安装

composer require madmatt/id3global-service

如果您尚未使用Composer进行依赖管理,请考虑这样做。如果您不希望这样做,您可以从版本发布部分下载最新版本。

使用方法

WSDL文件提供了可以提供的值的概述,这些值将因国家/地区而异。

请参阅完整代码示例,它提供了此模块使用情况的完整概述。

访问底层ID3global请求和响应

根据您的用例,您可能需要访问发送给ID3global的底层请求或ID3global API返回的响应。这种用例的典型示例是为了审计目的——例如,确认自上次进行身份验证以来身份信息没有发生变化。

为了方便起见,GlobalAuthenticationService类提供了一些辅助方法来让您访问底层数据。以下所有代码假设您已经调用了->verifyIdentity()方法,并且您有有效的BandText,或者您捕获了可能抛出的IdentityVerificationFailureException

// Assumes $service is an instance of ID3Global\Service\GlobalAuthenticationService

// Return the last SOAP request made to the ID3global API as a string
$lastRawRequest = $service->getLastRawRequest();

// Returns the SoapClient interpreted response from the API (this will be an object of type \stdClass, or null if the SOAP request failed entirely
// For example you can access the BandText of a valid response with $lastResponse->AuthenticateSPResult->BandText
$lastResponse = $service->getLastVerifyIdentityResponse();

// Access the underlying SoapClient object to perform more detailed debugging
$gateway = $service->getGateway(); // Returns a ID3Global\Gateway\GlobalAuthenticationGateway object
$soapClient = $gateway->getSoapClient(); // Returns a ID3Global\Gateway\SoapClient\ID3GlobalSoapClient object

// You can then do anything you'd normally do on SoapClient, such as:
$lastRawRequestHeaders = $soapClient->__getLastRequestHeaders(); // Returns an array of the headers sent to the API
$lastRawResponse = $soapClient->__getLastResponse(); // Returns the last response returned by the API

调试身份验证失败

在某些情况下,通常当ID3Global API产生意外结果时,您可能会收到一个IdentityVerificationFailureException。这可能在多种情况下发生,例如请求中缺少必需的字段或数据格式无效。

您还应在->verifyIdentity()调用中添加try/catch语句,以防止用户看到这些异常。

默认情况下,此库不通过异常消息暴露会泄露个人信息的信息,但如果您确信异常得到妥善处理(例如,被转发到符合GDPR的日志服务),则可以启用此功能。有时需要这种详细程度才能确定API请求失败的原因。

您可以通过以下配置启用异常消息中的此信息记录

$service = new ID3Global\Service\GlobalAuthenticationService;

// Must be set before calling ->verifyIdentity()
$service->setVerboseExceptionHandling(true);

// Either way, regardless of whether or not you enable verbose exception handling, IdentityVerificationFailureException will still contain the response
try {
    $service->verifyIdentity($identity, 'customer reference');
} catch (IdentityVerificationFailureException $e) {
    /** @var stdClass $response */
    $response = $e->getResponse();
}