braghetto / hokoml
简化 Mercado livre API 与您的应用程序之间通信的包。
2.2.2
2022-12-09 14:53 UTC
Requires
- php: >=5.5.9
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^7
- symfony/var-dumper: ^4.2
README
简化 Mercado livre API 与您的应用程序之间集成的包。
目录
安装
composer require braghetto/hokoml
配置
<?php $config = [ /** * Get app_id, secret_key and redirect_uri in te ML application manager (http://applications.mercadolibre.com/) */ 'app_id' => 'YOUR_APP_ID', 'secret_key' => 'YOUR_SECRET_KEY', 'redirect_uri' => 'YOUR_REDIRECT_URI', 'production' => false, /** * The ML code for your country * * MLA => Argentina * MBO => Bolivia * MLB => Brazil * MLC => Chile * MCO => Colombia * MCR => Costa Rica * MCU => Cuba * MRD => Dominican Republic * MEC => Ecuador * MGT => Guatemala * MHN => Honduras * MLM => Mexico * MNI => Nicaragua * MPA => Panama * MPY => Paraguay * MPE => Peru * MPT => Portugal * MSV => Salvador * MLU => Uruguay * MLV => Venezuela */ 'country' => 'YOUR_COUNTRY_CODE' ]
使用方法
认证
获取认证 URL
检索认证以授权您的应用程序。
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config); $url = $hokoml->getAuthUrl();
授权
获取代码后,检索访问令牌、用户 ID、过期时间和刷新令牌。
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config); $response = $hokoml->authorize($_GET['code']); // Persist the data for future usage...
刷新访问令牌
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config); // $refresh_token saved from your previous authorization $response = $hokoml->refreshAccessToken($refresh_token);
产品
创建
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config, $_SESSION['access_token'], $_SESSION['user_id']); $response = $hokoml->product()->create([ 'title' => 'TESTE RAY BAN', 'category_id' => 'MLB1227', 'price' => 900000, 'currency_id' => 'BRL', 'available_quantity' => 1, 'buying_mode' => 'buy_it_now', 'listing_type_id' => 'free', 'automatic_relist' => false, 'condition' => 'new', 'description' => 'Item:, <strong> Ray-Ban WAYFARER Gloss Black RB2140 901 </strong> Model: RB2140. Size: 50mm. Name: WAYFARER. Color: Gloss Black. Includes Ray-Ban Carrying Case and Cleaning Cloth. New in Box', 'warranty' => '12 month by Ray Ban', 'pictures' => [ ['source' => 'https://upload.wikimedia.org/wikipedia/commons/f/fd/Ray_Ban_Original_Wayfarer.jpg'], ['source' => 'https://upload.wikimedia.org/wikipedia/commons/a/ab/Teashades.gif'] ] ]);
查找产品
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config, $_SESSION['access_token'], $_SESSION['user_id']); $response = $hokoml->product()->find($product_id);
更新
并非所有信息都可以更新,因此包将过滤这些信息。 详情请见此处
<?php // [...] $response = $hokoml->product()->update($product_id, [ 'title' => 'Milibin', 'price' => 800000, 'warranty' => 'New warranty', // Won't be updated // [...] ]);
暂停
<?php // [...] $response = $hokoml->product()->pause($product_id);
恢复
<?php // [...] $response = $hokoml->product()->unpause($product_id);
完成
<?php // [...] $response = $hokoml->product()->finalize($product_id);
重新列出
<?php // [...] $response = $hokoml->product()->relist($product_id, $price); // $response = $hokoml->product()->relist($product_id, $price, $quantity = 1, $listing_type = 'free');
删除
<?php // [...] $response = $hokoml->product()->delete($product_id);
分类
列表
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config, $_SESSION['access_token'], $_SESSION['user_id']); // List all root categories $response = $hokoml->category()->list(); // List children categories for a given id. $response = $hokoml->category()->list($parent_category_id);
预测
预测给定标题的分类。
<?php // [...] $response = $hokoml->category()->predict('Rayban Gloss Black');
问题
提问
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config, $_SESSION['access_token'], $_SESSION['user_id']); $response = $hokoml->question()->ask($question_id, 'The questions.');
查找问题
<?php // [...] $response = $hokoml->question()->find($question_id);
回答
<?php // [...] $response = $hokoml->question()->answer($question_id, 'The answer.');
产品问题
列出产品的所有问题。
<?php // [...] $response = $hokoml->question()->fromProduct($product_id); // with filters $response = $hokoml->question()->fromProduct($product_id, [ 'status' => 'unanswered', [...] ]); // with filters and sorting $response = $hokoml->question()->fromProduct($product_id, ['status' => 'unanswered'], 'date_desc');
产品未回答的问题
列出产品的所有未回答问题。
<?php // [...] $response = $hokoml->question()->unansweredFromProduct($product_id);
封禁用户
<?php // [...] $response = $hokoml->question()->blockUser($user_id);
解封用户
<?php // [...] $response = $hokoml->question()->unblockUser($user_id);
已封禁的用户
列出已封禁的用户。
<?php // [...] $response = $hokoml->question()->blockedUsers();
收到的提问
<?php // [...] $response = $hokoml->question()->received(); //With filters $response = $hokoml->question()->received([ 'status' => 'unanswered' ]); //With filters and sorting $response = $hokoml->question()->received(['status' => 'unanswered'], 'date_desc');
用户
我
<?php use Braghetto\Hokoml\Hokoml; $hokoml = new Hokoml($config, $_SESSION['access_token'], $_SESSION['user_id']); $response = $hokoml->user()->me();
查找用户
<?php [...] $response = $hokoml->user()->find($user_id);
地址
检索认证用户的地址。
<?php [...] $response = $hokoml->user()->addresses();
接受的支付方式
检索认证用户接受的支付方式。
<?php [...] $response = $hokoml->user()->acceptedPaymentMethods();
许可证
此项目采用 MIT 许可证 - 请参阅 license.md 文件以获取详细信息