plhw/hf-api-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

plhw/hf-api-client

Composer 安装命令:

composer require plhw/hf-api-client

包简介

PLHW API Client provides means to authenticate clients against with OAuth2 server and issue authorized requests to our api endpoints

README 文档

README

PLHW API Client provides means to authenticate clients against our OAuth2 server and issue authorized requests to our api endpoints.

Installation

composer require plhw/hf-api-client

Example API calls

Once you have succesfully installed the application, some example scripts are located at. To use them first copy an configuration file to your app root.

cp ./vendor/plhw/hf-api-client/example/.hf-api-client-secrets.php.dist ./.hf-api-client-secrets.php

Open .hf-api-client-secrets.php and configure it with credentials you got from us.

Finally the example scripts are configured to use data/cache as directory for its cached accss tokens. This directory must exist (only for the examples).

Now you can run the example scripts;

php ./vendor/plhw/hf-api-client/example/practicesPos.php

Usage

To implement usage in your application you can have a look at the example scripts.

$options = \HF\ApiClient\Options\Options::fromArray(
    [
        'server_uri'    => 'https://api.plhw.nl',
        'client_id'     => 'id',
        'client_secret' => 'secret',    
        'scope'         => 'customer_pos',
        'grant_type'    => 'client_credentials',
    ]
);

$api = \HF\ApiClient\ApiClient::createClient($options, /* $cache OPTIONAL */);

The above is all that is nessesary to configure, though I recommend you tweak the caching meganism. Currently we use the zendframework/zend-cache component. This might change when v3 is released to use the psr-7 caching FIG standard.

When you have ApiClient instance you can use it by calling methods as defined in /vendor/plhw/hf-api-client/data/v1 on it. Additionally API documentation can be found here.

for example, search the published practices around a coordinate.

$results = $api->customer_posAroundCoordinate('52.3629882,4.8593175', 15000, 'insoles');

if ($api->isSuccess()) {
    foreach ($results['data'] as $result) {
        printf("Practice %s on %skm\n", $result['attributes']['name'],
            round(($result['attributes']['distance'] / 100)) / 10);
        printf(" - sells %s\n", implode(', ', $result['attributes']['products']));
    }
} else {
    printf("Error (%d): %s\n", $api->getStatusCode(), $result);
}

Under the hood

When you call any method on the APIClient instance an access token is requested from our OAuth2 server. This access token is then cached for aditional uses up to the moment it expires or is deleted. It will then get a new access token.

Any calls to our API are now signed with that access token and is used by our permission system to determain if you have access or not.

Our API will accept and return json payload with are automaticly (de)encoded.

OAuth2 ClientCredentialsGrant

For machine to machine communication OAuth2 ClientCredentialGrant is appropiate. You must obtain the following information from us.

  1. client ID
  2. client secret
  3. scope

Your client side application should communicate via a proxy to our server.


               
   [webbrowser] <----- internet ----->   [application]   <----- internet -----> [api.plhw.nl]

1.  request data    -> request ->      do we have valid access token?

2.                                     NO, get access token   -> request  -> id,secret,scope

3.                                                                                validate request

4.                                     store token in cache   <- response <- access token
                                                                     
5.                                     YES, request & token.  -> request  -> validate token

6.                                     data                   <- response <- data

7.  data             <- response <-    data

Run all examples in the 'commerce' domain:

find ./example/commerce/ -maxdepth 1 -type f -exec {} \;

Upgrading

v2 has been rewritten for php 8+. Principals are the same but there are a few minor changes that will break your application.

Please see our examples to see how you interact with the api.

plhw/hf-api-client 适用场景与选型建议

plhw/hf-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 763 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 plhw/hf-api-client 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 763
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2017-02-27