本教程显示了如何使用eBay Trading API配置eBay商店设置。 第1部分涵盖了开发人员仪表板和数据库设置;该部分重点介绍商店设置,第3部分涵盖了产品的添加。
>
密钥概念:
Ebay
类,以简化API请求,包括会话ID和用户令牌管理。>使用作曲家安装必要的库。创建:
这包括Slim(框架),SlimController(MVC支持),Guzzle(HTTP客户端),Valitron(form验证)和CodeGuy/upload(文件处理)。
composer.json
创建
{ "require": { "slim/slim-skeleton": "dev-master", "slimcontroller/slimcontroller": "dev-master", "guzzlehttp/guzzle": "4.*", "vlucas/valitron": "~1.2", "codeguy/upload": "*" }, "autoload": { "classmap": [ "controllers", "classes" ] } }
这可以设置Slim,Twig模板和数据库连接。
类(下面详细介绍)集成到容器中。index.php
>
态
<?php require 'vendor/autoload.php'; $app = new \SlimController\Slim([ 'templates.path' => 'templates' ]); $app->view(new \Slim\Views\Twig()); $app->view->parserOptions = [ 'charset' => 'utf-8', 'cache' => realpath('templates/cache'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true ]; $app->hook('slim.before', function () use ($app) { $app->view()->appendData(['baseUrl' => '/tester/ebay_trading_api']); }); $app->container->singleton('ebay', function () use ($app) { $id = 1; $settings_result = $app->db->query("SELECT user_token, run_name, dev_id, app_id, cert_id, site_id FROM settings WHERE id = $id"); $settings = $settings_result->fetch_object(); return new Ebay($settings); }); $app->container->singleton('db', function () { $server = 'localhost'; $user = 'user'; $pass = ''; $database = 'ebaytrading'; return new mysqli($server, $user, $pass, $database); }); $app->addRoutes([ '/' => 'Home:index', '/settings' => 'Settings:view', '/settings/update' => 'Settings:update', // ... other routes ... ]); $app->run();
方法使用guzzle来处理实际的API调用。Ebay
>
存储设置控制器():Ebay
>
classes/Ebay.php
<?php class Ebay { public $compatability_level = 885; public $sandbox_url = 'https://api.sandbox.ebay.com/ws/api.dll'; public $url = 'https://api.ebay.com/ws/api.dll'; // ... other properties ... public function __construct($settings) { // ... property assignment ... } public function request($method, $request_body) { // ... Guzzle request handling ... } public function getSessionID() { // ... GetSessionID API call ... } public function getUserToken($session_id) { // ... FetchToken API call ... } public function getUserPreferences() { // ... GetUserPreferences API call and data processing ... } public function getEbayDetails($detail_name) { // ... GeteBayDetails API call and data processing ... } }
request
>模板(in
>
controllers/Settings.php
<?php class Settings extends \SlimController\SlimController { public function viewAction() { // ... Fetches user preferences, shipping services, and store settings from DB and API. Renders 'settings/view.twig' ... } public function updateAction() { // ... Uses Valitron for validation, then updates store settings in the DB using prepared statements. Handles success/failure messages and redirects ... } }
Ebay
:用于查看和编辑商店设置的形式。
templates
更多详细信息:
以上是使用eBay Trading API配置商店的设置的详细内容。更多信息请关注PHP中文网其他相关文章!