Skip to content

获取产品列表

接口不做缓存处理,若有特殊场景: 秒杀、同设备多单抢购等可以定制。

TIP

请求接口(Header)必须携带参数,AppidAppSecret

text
请求方式(METHOD): POST
请求路径(URL): {url}/api/openapi/v1/products
请求参数(Argsments): payload: base64code

Payload

参数类型说明必传
machine_nostring设备编号(定长 8 位数字字符串)
pagestring分页, 默认: 1
per_pagestring分页大小, 默认: 10-
category_idstring商品分类, 默认: 0, 即查所有-
cabinet_namestring柜号, 默认: A, 取值范围 [A-Z]
(v1.13.0 新增)
-
select_allstring查询所有, 取值范围: ["0", "1"], 默认: "0"-
addrstring从机地址, 如: "1", 即第一块驱动器, 取值范围 ["1"-"8"]
(v1.25.0 新增)
-
timestampstring当前时间戳

cabinet_name, addr 不可同时传参

参数加密

对接示例

我们为您提供了 2 种语言 GO,PHP 的对接示例,如果您需要其他语言示例,请 联系我们

TIP

{url}默认为提供服务的地址

sh
package main

import (
 "fmt"
 "io"
 "net/http"
)

func main() {
    json := []byte(`{"payload": "eyJjYXRlZ29yeV9pZCI6MSwibWFjaGluZV*****iLCJwYWdlIjoxLCJwZXJfcGFnZSI6MTAsInNpZ24iOiIyMTlDMTZCREY0MkQzNjY4RkY1Qjg1QTMwRkU5N0Y1NCIsInRpbWVzdGFtcCI6IjE3MTMyNTU0MTEifQ=="}`)
 body := bytes.NewBuffer(json)

 // Create client
 client := &http.Client{}

 // Create request
 req, err := http.NewRequest("POST", "{url}/api/openapi/v1/products", body)

 // Headers
 req.Header.Add("Appid", "ds*******")
 req.Header.Add("AppSecret", "********")

 parseFormErr := req.ParseForm()
 if parseFormErr != nil {
   fmt.Println(parseFormErr)
 }

 // Fetch Request
 resp, err := client.Do(req)

 if err != nil {
  fmt.Println("Failure : ", err)
 }

 // Read Response Body
 respBody, _ := io.ReadAll(resp.Body)

 // Display Results
 fmt.Println("response Status : ", resp.Status)
 fmt.Println("response Headers : ", resp.Header)
 fmt.Println("response Body : ", string(respBody))
}
php
<?php

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$client = new Client();

$request = new Request(
        "POST",
        "{url}/api/openapi/v1/products",
        [
            "Appid" => "ds*******************",
            "AppSecret" => "*******************",
        ],
        "{\"payload\":\"eyJjYXRlZ29yeV9pZCI6MSwibWFjaGluZV9ubyI6Ijg2NjgzODA2MjUzNzU0OTIiLCJwYWdlIjoxLCJwZXJ*****sInRpbWVzdGFtcCI6IjE3MTMyNTU0MTEifQ==\"}");

$response = $client->send($request);
echo "Response HTTP : " . $response->getStatusCode();

请求结果(成功)

将以上 AppidAppSecret 进行修改成您商户的内容,运行结果:

json
{
  "code": 0,
  "message": "ok",
  "data": {
    "data": [
      {
        "id": 20,
        "category": {
          "id": 2,
          "title": "第二层"
        },
        "good": {
          "name": "可乐",
          "description": "可乐",
          "thumb": "{url}/storage/BkGv6Ij4Am/80b306a1-52db-4694-8de9-45181cc590be.png",
          "price": "0.10",
          "original_price": "0.00",
          "content": "<p>可口可乐</p>",
          "good_no": "412883701240",
          "slug": "412883701240"
        },
        "channel": {
          "name": "A21",
          "cabinet_name": "A",
          "code": "020",
          "x": "2",
          "y": "0",
          "addr": 1
        },
        "current_inventory": 1,
        "inventory": 2
      }
    ],
    "total": 6,
    "current_page": 1,
    "last_page": 1,
    "per_page": 10
  }
}

TIP

注意: 因接口返回的字段使用 protobuf, 部分字段值为空 或 false 时,默认不传

参数类型说明必传
dataobject产品内容
totalint总记录数
current_pageint当前页码
last_pageint最后一页
per_pageint分页数

查询结果为空时,data 默认返回空数组

json
{
  "code": 0,
  "message": "ok",
  "data": []
}

商品项说明

json
{
  "id": 20,
  "category": {
    "id": 2,
    "title": "第二层"
  },
  "good": {
    "name": "可乐",
    "description": "可乐",
    "thumb": "{url}/storage/BkGv6Ij4Am/80b306a1-52db-4694-8de9-45181cc590be.png",
    "price": "0.10",
    "original_price": "0.00",
    "content": "<p>可口可乐</p>",
    "good_no": "412883701240",
    "slug": "412883701240"
  },
  "channel": {
    "name": "A21",
    "cabinet_name": "A",
    "code": "020",
    "x": "2",
    "y": "0",
    "addr": 1
  },
  "current_inventory": 1,
  "inventory": 2
}
参数类型说明必传
idint产品ID
current_inventoryint当前库存
inventoryint最大库存
category-object商品分类
idint分类ID
titlestring分类名称
good-object商品内容
namestring名称
descriptionstring介绍
thumbstring封面
pricestring价格
original_pricestring原价
contentstring富文本内容
good_nostring商品编码
slugstring商品编码 v1.2.3 新增字段
mediaarray图片轮播图-
channel-object货道信息
namestring货道名
cabinet_namestring柜号
codestring电机号, 默认从000开始,即第一行第一列; 200, 为副柜第一行第一列
xstring行, 默认从0开始,即第一行
ystring列, 默认从0开始,即第一列
addrint从机地址, 默认从1开始,即第一个驱动板

请求结果(失败)

根据返回的 错误代码 进行排查:

json
{
  "code": 30002,
  "message": "设备已离线",
  "data": {}
}

© All rights reserved. 广州鼎商金属制品有限公司