Files
ircloud-assistant/skills/irun-yidianhuo/product-suite.md

147 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 商品搜索接口(新版)
> 用于通过商品名称或编码查询商品关键信息,是创建订单的前置步骤。
## 认证流程
### 第一步:登录获取 JWT
```
POST https://accounts.77ircloud.com/api/v2/accounts/login
Content-Type: application/json
```
**请求体:**
```json
{
"userName": "112983083",
"password": "77ircloud",
"loginServerType": 4
}
```
**返回的 jwtToken 即为 authorization 值:**
```json
{
"code": 200,
"data": {
"jwtToken": "eyJhbGci...",
"expires_in": 604800000
}
}
```
### 第二步:带 JWT 请求商品接口
请求头:
- `authorization`: `{jwtToken}`**注意:没有 Bearer 前缀**
- `x-exclude-login-mutex`: `77ircloud` — 固定值
## 商品搜索
```
GET https://suite.77ircloud.com/product-aggregation/v1/products?pageSize=30&currentPage=1&queryTag=true&queryInventories=true&loadSortingTag=true&loadSortingTagName=true&q={关键词}
```
**参数说明:**
| 参数 | 必填 | 说明 |
|------|------|------|
| `q` | ✅ | 搜索关键词(商品名称或商品编码) |
| `pageSize` | ✅ | 每页数量 |
| `currentPage` | ✅ | 页码从1开始 |
| `queryTag` | 可选 | 是否查询标签 |
| `queryInventories` | 可选 | 是否查询库存 |
| `loadSortingTag` | 可选 | 是否查询分拣标签 |
| `loadSortingTagName` | 可选 | 是否查询分拣标签名称 |
**返回示例:**
```json
{
"code": 200,
"data": {
"totalCount": 4,
"currentPage": 1,
"pageSize": 30,
"items": [
{
"name": "嘉吉尚选霸王鸡肉条1kg",
"skuId": 2116793372668192,
"multiUnitId": 2116793372668193,
"unitName": "包",
"basePrice": 18.9,
"availableAmount": 1035.0,
"specJson": "{\"规格\":\"包=约33片/包、件=1kg*10包\"}",
"code": "165-009-00068",
"levelPrices": [
{"index": 1, "price": 18.9},
{"index": 2, "price": 18.0},
{"index": 3, "price": 19.5},
{"index": 4, "price": 18.5}
]
}
]
}
}
```
## 关键字段说明
| 字段 | 说明 | 用途 |
|------|------|------|
| `skuId` | 商品SKU ID | 下单时用 `productSku` |
| `multiUnitId` | 单位ID | 下单时用 `unitId` |
| `unitName` | 单位名称(如"包" | 展示用 |
| `basePrice` | 参考单价 | 填写 `salePrice``originalPrice` |
| `availableAmount` | 当前可用库存 | 判断是否充足 |
## 完整调用示例
```python
import urllib.request, json, urllib.parse
# Step 1: 登录获取 JWT
login_data = json.dumps({
"userName": "112983083",
"password": "77ircloud",
"loginServerType": 4
}).encode()
login_req = urllib.request.Request(
"https://accounts.77ircloud.com/api/v2/accounts/login",
data=login_data,
headers={"Content-Type": "application/json"},
method="POST"
)
with urllib.request.urlopen(login_req, timeout=10) as resp:
jwt = json.loads(resp.read())['data']['jwtToken']
# Step 2: 搜索商品
keyword = "嘉吉尚选霸王鸡肉条"
q = urllib.parse.quote(keyword)
url = f"https://suite.77ircloud.com/product-aggregation/v1/products?pageSize=30&currentPage=1&queryTag=true&queryInventories=true&loadSortingTag=true&loadSortingTagName=true&q={q}"
search_req = urllib.request.Request(url, headers={
"authorization": jwt,
"x-exclude-login-mutex": "77ircloud"
})
with urllib.request.urlopen(search_req, timeout=15) as resp:
data = json.loads(resp.read())
items = data.get('data', {}).get('items', [])
for item in items:
print(f"商品: {item['name']}")
print(f" skuId: {item['skuId']}")
print(f" multiUnitId: {item['multiUnitId']}")
print(f" 单位: {item['unitName']}")
print(f" 库存: {item['availableAmount']}")
```
## 注意事项
1. **每次查询都需要重新登录获取 JWT**有效期约7天
2. **authorization 没有 Bearer 前缀**,直接写 JWT 字符串
3. **搜索关键词用 URL 编码**,中文需要 encode
4. **搜索结果可能为空**,可尝试不同的关键词组合(如品牌名、商品简称等)