divido/pca-predict

此包已被放弃且不再维护。未建议替代包。

一个小型库,用于使用Finder/Retriever PCA Predict API

0.2.3 2017-05-09 15:07 UTC

This package is not auto-updated.

Last update: 2020-08-22 05:52:23 UTC


README

用于与PCA Predict API交互的库

目录

用法

凭证

将您的API密钥包装到Credentials类中,然后可以在多个PCA Predict API中使用它。

Credentials类接受一个参数,即您的API密钥。

use \DividoFinancialServices\PCAPredict\Credentials;

$credentials = new Credentials('YOUR-API-KEY');

电子邮件验证

EmailValidation API接受一个电子邮件地址并验证它,返回一些元信息。

<?php

// Create a credentials object (for use with both API's)
$credentials = new Credentials('Your-API-Key-Here');

// Create an email validator
$validator = new EmailValidator($credentials);

// Create arguments object
$args = new EmailValidatorArgs(); // Default timeout is 5 seconds, can be overridden
$args->setEmailAddress('test@test.com');

// Validate email address
$results = $validator->validate($args);

// Dump result
print_r($results);
# output 
DividoFinancialServices\PCAPredict\EmailValidatorResult Object
(
    [responseCode:private] => Valid_CatchAll
    [responseMessage:private] => Mail is routable to the domain but account could not be validated
    [emailAddress:private] => test@test.com
    [userAccount:private] => test
    [domain:private] => test.com
    [isDisposableOrTemporary:private] => true
    [isComplainerOrFraudRisk:private] => true
    [duration:private] => 0.777
)

电话号码验证

PhoneNumberValidation API接受一个电话号码并验证它,返回一些元信息。

<?php

// Create a credentials object (for use with both API's)
$credentials = new Credentials('Your-API-Key-Here');

// Create an phone number validator
$validator = new PhoneValidator($credentials);

// Create arguments object
$args = new PhoneValidatorArgs(); 
$args->setPhoneNumber('+447515123456');

// If the phone number is in local format, then we should specify country code too. e.g.
$args->setPhoneNumber('07515123456');
$args->setCountryCode('GB');

// Validate phone number
$results = $validator->validate($args);

// Dump result
print_r($results);
# output 
DividoFinancialServices\PCAPredict\PhoneValidatorResult Object
(
    [phoneNumber:private] => +447515123456
    [validationSucceeded:private] => 1
    [isValid:private] => Yes
    [networkCode:private] => 10
    [networkName:private] => Telefonica UK
    [networkCountry:private] => GB
    [nationalFormat:private] => 07515 123456
    [countryPrefix:private] => 44
    [numberType:private] => Mobile
)

银行账户验证

BankAccountValidation API接受一个银行账户号码和支票编码并验证它,返回额外的元数据。

<?php

// Create a credentials object (for use with both API's)
$credentials = new Credentials('Your-API-Key-Here');

// Create an bank accoujnt validator
$validator = new BankAccountValidator($credentials);

// Create arguments object
$args = new BankAccountValidatorArgs(); 
$args->setAccountNumber('12345678');
$args->setSortCode('00-00-99');

// Validate bank details
$results = $validator->validate($args);

// Dump result
print_r($results);
# output 
DividoFinancialServices\PCAPredict\BankAccountValidatorResult Object
(
    [isCorrect:private] => 1
    [isDirectDebitCapable:private] => 1
    [statusInformation:private] => CautiousOK
    [correctedSortCode:private] => 000099
    [correctedAccountNumber:private] => 12345678
    [iban:private] => GB27NWBK00009912345678
    [bank:private] => TEST BANK PLC PLC
    [bankBic:private] => NWBKGB21
    [branch:private] => Worcester
    [branchBic:private] => 18R
    [contactAddressLine1:private] => 2 High Street
    [contactAddressLine2:private] => Smallville
    [contactPostTown:private] => Worcester
    [contactPostcode:private] => WR2 6NJ
    [contactPhone:private] => 01234 456789
    [contactFax:private] => 
    [fasterPaymentsSupported:private] => 
    [chapsSupported:private] => 1
)

地址查找器

Finder API接受一个模糊文本字符串并将其与一个或多个地理类型匹配。

要使用Finder API,首先设置一些FinderArgs

地址查找器参数。

FinderArgs类封装用于搜索Finder API的参数。

use \DividoFinancialServices\PCAPredict\FinderArgs();
$finderArgs = new FinderArgs();

文本(搜索查询)

设置要搜索的字符串。 必需
$finderArgs->setText("Interchange, Stables Market");

限制结果

设置返回的结果数量。默认为8。 可选
$finderArgs->setLimit(2));

国家过滤

限制结果仅限于某些国家。可以是空的(允许结果中包含任何国家)或是一个2位国家代码数组(例如GB)。 可选
$finderArgs->setCountries([
    'GB',
]);

结果类型过滤

限制结果为特定类型的结果。可以为空(允许所有结果类型)。可以是一个结果类型的数组: 地址区域 建筑名称 街道 注意 只有 地址 结果类型可以被输入到 检索器 API 中以获取更详细的信息。 可选
$finderArgs->setTypeFilter([
    FinderArgs::FILTER_TYPE_ADDRESS,
    FinderArgs::FILTER_TYPE_LOCALITY,
]);

// or indivudually

$finderArgs->addTypeFilter(FinderArgs::FILTER_TYPE_ADDRESS);
$finderArgs->addTypeFilter(FinderArgs::FILTER_TYPE_LOCALITY);

使用 Finder API 和 Finder 参数对象

// Create a credentials object (for use with both API's)
$credentials = new Credentials('Your-API-Key-Here');

// Create a Finder
$finder = new Finder($credentials);

// Create finder argumennts (search/query)
$args = new FinderArgs();
$args->setText('Interchange, Stables Market')
  ->setLimit(1)
  ->setCountries(['GB',])
  ->setTypeFilter([FinderArgs::FILTER_TYPE_ADDRESS,])

// Search for address
$results = $finder->find($args);

// Dump result
print_r($results);
# output 
Array
(
    [0] => DividoFinancialServices\PCAPredict\FinderResult Object
        (
            [id:protected] => GB|RM|A|54205818
            [type:protected] => Address
            [text:protected] => Interchange, The Stables Market Chalk Farm Road
            [highlight:protected] => 0-11
            [description:protected] => London, NW1 8AH
        )

)

地址检索器

检索器 API 接收 PCA Predict 地址 ID(从 Finder 调用返回)并返回有关地址的更详细的信息。

<?php

// Create a credentials object (for use with both API's)
$credentials = new Credentials('Your-API-Key-Here');

// Create a Retriever
$retriever = new Retriever($credentials);

// Search for address
$results = $retriever->retrieve('GB|RM|A|54205818'); // This ID MUST be of type 'Address'. Other types will not work.

// Dump result
print_r($results);
# output 
DividoFinancialServices\PCAPredict\RetrieveResult Object
(
    [id:protected] => GB|RM|A|54205818
    [domesticId:protected] => 54205818
    [language:protected] => ENG
    [languageAlternatives:protected] => ENG
    [department:protected] =>
    [company:protected] => Interchange
    [subBuilding:protected] =>
    [buildingNumber:protected] =>
    [buildingName:protected] =>
    [secondaryStreet:protected] => The Stables Market
    [street:protected] => Chalk Farm Road
    [block:protected] =>
    [neighbourhood:protected] =>
    [district:protected] =>
    [city:protected] => London
    [line1:protected] => The Stables Market
    [line2:protected] => Chalk Farm Road
    [line3:protected] =>
    [line4:protected] =>
    [line5:protected] =>
    [adminAreaName:protected] => Camden
    [adminAreaCode:protected] =>
    [province:protected] =>
    [provinceName:protected] =>
    [provinceCode:protected] =>
    [postalCode:protected] => NW1 8AH
    [countryName:protected] => United Kingdom
    [countryIso2:protected] => GB
    [countryIso3:protected] => GBR
    [countryIsoNumber:protected] => 826
    [sortingNumber1:protected] => 77214
    [sortingNumber2:protected] =>
    [barcode:protected] => (NW18AH5PW)
    [poBoxNumber:protected] =>
    [label:protected] => Interchange
The Stables Market
Chalk Farm Road
LONDON
NW1 8AH
UNITED KINGDOM
    [type:protected] => Commercial
    [dataLevel:protected] => Premise
)

测试

# Example 

$ vendor/bin/phpunit

PHPUnit 5.7.17 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 86 ms, Memory: 4.00MB

OK (4 tests, 47 assertions)