clientId = $clientId; $this->apiKey = $apiKey; } private function request($path, $data = []) { $url = $this->host . $path; $headers = [ 'Client-Id: ' . $this->clientId, 'Api-Key: ' . $this->apiKey, 'Content-Type: application/json', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $res = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return [ 'http' => $code, 'body' => json_decode($res, true) ]; } // 商品列表 public function v2_product_list($page = 1, $size = 10) { return $this->request('/v2/product/list', [ 'page' => $page, 'page_size' => $size ]); } // 商品信息 public function v2_product_info($product_id = 0, $offer_id = '') { return $this->request('/v2/product/info', [ 'product_id' => (int)$product_id, 'offer_id' => $offer_id ]); } // 商品库存 public function v2_product_stocks($sku = []) { return $this->request('/v2/product/info/stocks', [ 'sku' => $sku ]); } // 商品价格 public function v1_product_prices($product_id = []) { return $this->request('/v1/product/info/prices', [ 'product_id' => $product_id ]); } // 订单列表 public function v3_order_list($status = 'delivered', $limit = 10) { return $this->request('/v3/order/list', [ 'filter' => [ 'status' => $status ], 'limit' => $limit, 'sort' => 'ASC' ]); } // 订单详情 public function v3_order_info($order_id) { return $this->request('/v3/order/info', [ 'order_id' => (int)$order_id ]); } // 店铺信息 public function v1_info() { return $this->request('/v1/info', []); } // 店铺余额 public function v1_finance_balance() { return $this->request('/v1/finance/balance', []); } // 修改库存 public function v1_product_stocks_update($stocks) { return $this->request('/v1/product/stocks', $stocks); } // 修改价格 public function v1_product_price_update($prices) { return $this->request('/v1/product/price', $prices); } // 分类树 public function v1_category_tree() { return $this->request('/v1/category/tree', []); } // 退款列表 public function v1_refund_list($limit = 10) { return $this->request('/v1/refund/list', [ 'limit' => $limit ]); } } // 初始化 $ozon = null; $result = []; $error = ''; // 保存密钥 if (isset($_POST['save_key'])) { $cid = trim($_POST['client_id']); $key = trim($_POST['api_key']); if ($cid && $key) { $_SESSION['cid'] = $cid; $_SESSION['key'] = $key; header('Location: ozon_api.php'); exit; } else { $error = '请填写完整密钥'; } } // 创建实例 if ($_SESSION['cid'] && $_SESSION['key']) { $ozon = new OzonApi($_SESSION['cid'], $_SESSION['key']); } // 执行接口 if ($ozon && isset($_POST['act'])) { $act = $_POST['act']; $p = $_POST['p']; switch ($act) { case 'product_list': $result = $ozon->v2_product_list((int)$p['page'], (int)$p['size']); break; case 'product_info': $result = $ozon->v2_product_info((int)$p['product_id'], $p['offer_id']); break; case 'product_stocks': $sku = array_map('intval', explode(',', $p['sku'] ?? '')); $sku = array_filter($sku); $result = $ozon->v2_product_stocks(array_values($sku)); break; case 'product_prices': $ids = array_map('intval', explode(',', $p['ids'] ?? '')); $ids = array_filter($ids); $result = $ozon->v1_product_prices(array_values($ids)); break; case 'order_list': $result = $ozon->v3_order_list($p['status'], (int)$p['limit']); break; case 'order_info': $result = $ozon->v3_order_info((int)$p['order_id']); break; case 'shop_info': $result = $ozon->v1_info(); break; case 'balance': $result = $ozon->v1_finance_balance(); break; case 'update_stock': $result = $ozon->v1_product_stocks_update([ 'stocks' => [ [ 'product_id' => (int)$p['pid'], 'stock' => (int)$p['stock'] ] ] ]); break; case 'update_price': $result = $ozon->v1_product_price_update([ 'prices' => [ [ 'product_id' => (int)$p['pid'], 'price' => (float)$p['price'], 'old_price' => (float)$p['old_price'] ] ] ]); break; case 'category': $result = $ozon->v1_category_tree(); break; case 'refund': $result = $ozon->v1_refund_list((int)$p['limit']); break; } } function j($d) { return json_encode($d, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); } ?> OZON API 可视化管理工具

OZON API 可视化一键调用工具


🔑 OZON 密钥配置


$error"; ?>

🚀 接口快速调用

页码: 条数:
商品ID:
SKU(逗号分隔):
商品ID: 库存:
商品ID(逗号分隔):
商品ID: 售价: 原价:
状态: 条数:
订单ID:
条数:

📄 返回结果

HTTP 状态码:

请先配置 Client ID 和 API Key