定制 optimaize/nameapi-client-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

optimaize/nameapi-client-php

Composer 安装命令:

composer require optimaize/nameapi-client-php

包简介

PHP Client for the NameAPI Web Service

README 文档

README

PHP Client for the NameAPI Web Service at http://www.nameapi.org/

All you need to send requests is your own api key, get it from nameapi.org.

Library setup

The recommended way is to use Composer. The project at https://github.com/optimaize/nameapi-client-php-example-composer shows how that's done.

You can download the source code and make it available to your code. Or you can check it out directly from this GitHub project. Currently there is no phar available.

The only requirement is that the php_curl extension is enabled.

Functional tests

Functional tests that demonstrate how the services work, and that they work, are in https://github.com/optimaize/nameapi-client-php-functionaltests you can look at the code, and you can even run those tests using your api key and PHPUnit.

Setup code

At first you need one single include, the one to the nameapi service factory:

require_once('your/path/to/org/nameapi/client/services/ServiceFactory.php');

Then you need a Context that explains a bit your working environment, something like:

use org\nameapi\ontology\input\context\Context;
use org\nameapi\ontology\input\context\Priority;
$context = Context::builder()
    ->place('US')
    ->priority(Priority::REALTIME())
    ->build();

Then you can already create the service factory which gives you access to all nameapi services:

$serviceFactory = new ServiceFactory('your-api-key', $context);

Send a ping

This code sends a simple ping to nameapi to test the connection:

$ping = $serviceFactory->systemServices()->ping();
$pong = $ping->ping();

If the response is 'pong' then all is fine and you can move on to the real goodies.

Input / Output

All input objects come with builders or nicely documented setters. The result objects returned by the services all have fully documented getters. Many input arguments are optional - that means you can start simple, and add more as you need.

Behind the scenes this service api uses REST. But luckily you don't need to worry about any of the interface detail, you can just use the provided classes.

Person input object

Most services accept a 'Person' as input. This person contains a name, and optionally more data such as gender, birth date etc. The name can be just a single "full name" string, or it can be composed of multiple fields like given name, middle name, surname. This standardized api makes it simple to use different services in a consistent way, and is very convenient in accepting the data however you have it at hands.

Creating a simple person looks something like this:

use org\nameapi\ontology\input\entities\person\NaturalInputPerson;
use org\nameapi\ontology\input\entities\person\name\InputPersonName;
$inputPerson = NaturalInputPerson::builder()
    ->name(InputPersonName::westernBuilder()
        ->fullname( "John F. Kennedy" )
        ->build())
    ->build();

Name Parser

Name parsing is the process of splitting a full name into its components.

Using the $inputPerson created earlier:

$personNameParser = $this->makeServiceFactory()->parserServices()->personNameParser();
$parseResult = $personNameParser->parse($inputPerson);
var_dump($parseResult);

Name Genderizer

Name genderizing is the process of identifying the gender based on a person's name.

Using the $inputPerson created earlier:

$personGenderizer = $serviceFactory->genderizerServices()->personGenderizer();
$personGenderResult = $personGenderizer->assess($inputPerson);
echo $personGenderResult->getGender()->toString(); //will print 'MALE'

Name Matcher

The Name Matcher compares names and name pairs to discover whether the people could possibly be one and the same person.

This service takes 2 people as input:

$personMatcher = $serviceFactory->matcherServices()->personMatcher();
$inputPerson1 = NaturalInputPerson::builder()
    ->name(InputPersonName::westernBuilder()
        ->fullname( "John F. Kennedy" )
        ->build())
    ->build();
$inputPerson2 = NaturalInputPerson::builder()
    ->name(InputPersonName::westernBuilder()
        ->fullname( "Jack Kennedy" )
        ->build())
    ->build();
$personMatcherResult = $personMatcher->match($inputPerson1, $inputPerson2);
echo $personMatcherResult->getPersonMatchType()->toString(); //will print 'MATCHING'

Name Formatter

The Name Formatter displays personal names in the desired form. This includes the order as well as upper and lower case writing.

$personNameFormatter = $serviceFactory->formatterServices()->personNameFormatter();
$inputPerson = NaturalInputPerson::builder()
    ->name(InputPersonName::westernBuilder()
        ->fullname( "john kennedy" )
        ->build())
    ->build();
$formatterResult = $personNameFormatter->format($inputPerson, new FormatterProperties());
echo $formatterResult->getFormatted(); //will print 'John Kennedy'

Email Name Parser

The Email Name Parser extracts names out of email addresses.

$emailNameParser = $serviceFactory->emailServices()->emailNameParser();
$result = $emailNameParser->parse("john.doe@example.com");
echo $result;

Disposable Email Address Detector

The DEA-Detector checks email addresses against a list of known "trash domains" such as mailinator.com.

$deaDetector = $serviceFactory->emailServices()->disposableEmailAddressDetector();
$result = $deaDetector->isDisposable("abcdefgh@10minutemail.com");
echo $result->getDisposable()->toString()); //will print 'YES'

Risk Detector

The Risk-Detector checks all data in the person input, including the name, address, birthdate, email address and phone number for fake and suspicious data.

$riskDetector = $serviceFactory->riskServices()->personRiskDetector();
$riskResult = $riskDetector->detect($inputPerson);
var_dump($riskResult);

optimaize/nameapi-client-php 适用场景与选型建议

optimaize/nameapi-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120.58k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2015 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 optimaize/nameapi-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 optimaize/nameapi-client-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 optimaize/nameapi-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 120.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 27
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2015-11-13