wandesnet/mercado-livre
最新稳定版本:1.2.5
Composer 安装命令:
composer require wandesnet/mercado-livre
包简介
PHP SDK for integration with Mercado Livre
关键字:
README 文档
README
This integration package with Mercado Livre (not the official one)
Required
- PHP 8.1+
Installation
composer require wandesnet/mercado-livre
Usage
Create a class Meli extends from Meli Connector and implement the methods requires:
The refreshTokenExpireIn method is free for you to implement as per your logic for refreshing the token; See the example below:
Set setClientId, setClientSecret, setRedirectUri change the settings:
final class Meli extends MeliConnector { public ?int $tries = 2; // default 1, try to request api 2 times if fail public function resolveBaseUrl(): string { return 'https://api.mercadolibre.com'; } protected function defaultOauthConfig(): OAuthConfig { return OAuthConfig::make() ->setClientId('3232321') ->setClientSecret('fs4343fs423') ->setAuthorizeEndpoint('https://auth.mercadolivre.com.br/authorization') ->setRedirectUri('http://my-site.com/callback.php') ->setTokenEndpoint('oauth/token'); } protected function refreshTokenExpireIn(): void { if ($this->hasExpired()) { $refresh = $this->refreshAccessToken($this->refresh_token); $this->access_token = $refresh->getAccessToken(); $this->refresh_token = $refresh->getRefreshToken(); $this->expires_in = $refresh->getExpiresAt()->getTimestamp(); } } }
Example of use Meli::make() or new Meli():
$response = Meli::make('access_token', 'refresh_token', 'expire_in')->auth()->request()->order(123456789);
Example to generate authentication url in Mercado Livre:
Meli::make()->getAuthorizationUrl();
Example to get access_token after authentication in Mercado Livre:
$authenticator = Meli::make()->getAccessToken($_GET['code']); var_dump($authenticator->getAccessToken(), $authenticator->getRefreshToken(), $authenticator->getExpiresAt()->getTimestamp());
Tests
./vendor/bin/pest
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-06