5分钟快速接入API
首先需要在管理后台申请API访问密钥:
// 登录管理后台
// 进入"系统设置" → "API管理"
// 点击"创建API密钥"
// 保存生成的API Key和Secret
选择适合您开发语言的SDK进行安装:
npm install @niumall/sdk
pip install niumall-sdk
<dependency>
<groupId>com.niumall</groupId>
<artifactId>sdk</artifactId>
<version>1.0.0</version>
</dependency>
使用SDK创建采购订单:
const { NiuMallClient } = require('@niumall/sdk');
const client = new NiuMallClient({
apiKey: 'your-api-key',
apiSecret: 'your-api-secret',
baseUrl: 'https://wapi.nanniwan.com/v1'
});
// 创建采购订单
const order = await client.orders.create({
supplierId: 'supplier-123',
productType: 'beef_cattle',
quantity: 50,
unitPrice: 15000,
deliveryDate: '2024-03-15'
});
console.log('订单创建成功:', order);
from niumall import NiuMallClient
client = NiuMallClient(
api_key='your-api-key',
api_secret='your-api-secret',
base_url='https://wapi.nanniwan.com/v1'
)
# 创建采购订单
order = client.orders.create({
'supplier_id': 'supplier-123',
'product_type': 'beef_cattle',
'quantity': 50,
'unit_price': 15000,
'delivery_date': '2024-03-15'
})
print('订单创建成功:', order)
完整的API接口说明
所有API请求都需要在请求头中包含认证信息:
Authorization: Bearer {access_token}
或者
X-API-Key: your-api-key
X-API-Secret: your-api-secret
创建采购订单
{
"supplierId": "string", // 供应商ID
"productType": "string", // 产品类型
"quantity": "number", // 采购数量
"unitPrice": "number", // 单价(元)
"deliveryDate": "string", // 交货日期
"remarks": "string" // 备注信息
}
{
"code": 200,
"message": "success",
"data": {
"orderId": "order-123456",
"status": "pending",
"createdAt": "2024-01-15T10:30:00Z"
}
}
获取订单详情
{
"code": 200,
"message": "success",
"data": {
"orderId": "order-123456",
"supplierId": "supplier-123",
"productType": "beef_cattle",
"quantity": 50,
"unitPrice": 15000,
"totalAmount": 750000,
"status": "confirmed",
"deliveryDate": "2024-03-15",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T11:00:00Z"
}
}
获取供应商列表
?page=1&limit=20&type=beef_cattle
{
"code": 200,
"message": "success",
"data": {
"items": [
{
"supplierId": "supplier-123",
"name": "某某养殖场",
"type": "beef_cattle",
"contact": "张经理",
"phone": "13800138000",
"address": "某省某市某区"
}
],
"total": 100,
"page": 1,
"limit": 20
}
}
多种编程语言的SDK使用说明
适用于JavaScript/TypeScript开发的SDK,支持异步操作和Promise。
npm install @niumall/sdk
const { NiuMallClient } = require('@niumall/sdk');
const client = new NiuMallClient({ apiKey, apiSecret });
适用于Python开发的SDK,支持同步和异步请求。
pip install niumall-sdk
from niumall import NiuMallClient
client = NiuMallClient(api_key, api_secret)
适用于Java开发的SDK,支持Spring Boot集成。
<dependency>
<groupId>com.niumall</groupId>
<artifactId>sdk</artifactId>
<version>1.0.0</version>
</dependency>
NiuMallClient client = new NiuMallClient(apiKey, apiSecret);
适用于PHP开发的SDK,支持Composer管理。
composer require niumall/sdk
$client = new NiuMallClient($apiKey, $apiSecret);