定制 coffeedesk/allegro-api-client-php 二次开发

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

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

coffeedesk/allegro-api-client-php

最新稳定版本:3.1.1

Composer 安装命令:

composer require coffeedesk/allegro-api-client-php

包简介

README 文档

README

Helper model and connector classes for allegro integration.

Parts of the library is automatically generated by the OpenAPI Generator project using swagger definition from allegro:

https://developer.allegro.pl/swagger.yaml

Installation with composer

composer require coffeedesk/allegro-api-client-php

Api documentation

This package was implemented according to:

https://developer.allegro.pl/documentation/

Usage

OAuth

Implementation OAuth according to https://developer.allegro.pl/auth/

1 Stage: Get code from callback

<?php

require_once(__DIR__ . '/vendor/autoload.php');

$authenticator = new \AllegroApi\Authentication\Authenticator(
    new \GuzzleHttp\Client(),
    'https://allegro.pl.allegrosandbox.pl',
    'ALLEGRO_CLIENT_ID', // after add this app to allegro sandbox panel you will get this
    'ALLEGRO_CLIENT_SECRET', // after add this app to allegro sandbox panel you will get this
    'http://uri.where.is.sent.callback/authorization_callback' // after authorization callback will be sent on url (you can use serveo.net localy)
);

echo $authenticator->getAuthorizeUrl();

// This shows url to allegro OAuth, you can redirect in your app to this url in your controller.

?>

2 Stage: Get tokens from callback after authorization - e.g. http://uri.where.is.sent.callback/authorization_callback

Make controller under your callback url, allegro will send you tokens after login.

$authorizationToken = $_GET['code'];
$tokens = $authenticator->getAuthenticationTokensFromAuthorizationToken($authorizationToken);

3 Stage: Use received access token in every request

<?php

require_once(__DIR__ . '/vendor/autoload.php');

$configuration = (new \AllegroApi\Configuration())
    ->setHost('https://api.allegro.pl.allegrosandbox.pl')
    ->setAccessToken('access.token.received.from.callback.authorize.url');

$offerManagmentApi = new \AllegroApi\Client\OfferManagementApi(
    new \GuzzleHttp\Client(),
    $configuration
);

$categories = $offerManagmentApi->getCategoriesUsingGET();

var_dump($categories);

?>

Refresh token

To refresh allegro token you might need get current token from your repository


<?php

require_once(__DIR__ . '/vendor/autoload.php');

$authenticator = new \AllegroApi\Authentication\Authenticator(
    new \GuzzleHttp\Client(),
    'https://allegro.pl.allegrosandbox.pl',
    'ALLEGRO_CLIENT_ID', // after add this app to allegro sandbox panel you will get this
    'ALLEGRO_CLIENT_SECRET', // after add this app to allegro sandbox panel you will get this
    'http://uri.where.is.sent.callback/authorization_callback' // after authorization callback will be sent on url (you can use serveo.net localy)
);

// your repository 
$tokenData = $allegroTokenRepository->getCurrentToken();

$newTokenData = $authenticator->getNewTokensFromCurrentTokens($tokenData['refresh_token']);

// your repository 
$allegroTokenRepository->allegroTokenRepository->saveToken($newTokenData);

Code Notice: Best way to use authenticator and AllegroApi classes is Dependency Injection. To define configuration(\AllegroApi\Configuration) you can use factory pattern.

Development

Generate php classes using openapi-generator

ATTENTION!

Please look at commit 070d13ed2d031c8361597aead4071a78b6317ba6 in this repo. Package openapi-generator always generate wrong CategoryParameters.php. You have to fix it every time you regenerate this code.

To generate new clients and models run:

docker run --rm \
-v ${PWD}:/local/project \
-v ${PWD}/src:/local/out/php/lib \
openapitools/openapi-generator-cli generate \
-i /local/project/swagger.yaml \
-g php \
-o /local/out/php \
--invoker-package AllegroApi \
--api-package Client \
--model-package Model

统计信息

  • 总下载量: 1.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固