模拟数据生成
按字段列表或预设模板批量生成用户、订单等模拟测试数据,支持显式 type 与嵌套对象
## 功能说明
按字段列表或预设 schema 批量生成模拟测试数据,适用于前端联调、接口 Mock、演示环境等场景。
## 请求参数
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| count | int | 否 | 生成条数,默认 1,最大 100 |
| schema | string | 否 | 预设模板:`user`(用户)、`order`(订单)、`product`(商品)、`address`(地址)、`article`(文章)、`comment`(评论) |
| fields | array | 否 | 自定义字段列表;与 schema 同时传入时会合并,同名字段以 fields 为准 |
### fields 写法
- 字符串:`"phone"` — 按字段名自动推断类型
- 对象:`{"name":"age","type":"int","min":18,"max":60}` — 显式指定类型
- 嵌套:`{"name":"buyer","type":"user"}` — 生成完整用户对象
## 常用 field type
`string` `int` `float` `bool` `text` `enum` `name` `phone` `email` `idcard` `address` `date` `datetime` `url` `uuid` `ip` `avatar` `money` `order_no` `product_name` `user` `order` `product` `article` `comment`
## 示例
### 预设用户模板
```json
{"count": 10, "schema": "user"}
```
### 预设订单模板
```json
{"count": 5, "schema": "order"}
```
### 自定义字段
```json
{
"count": 3,
"fields": ["name", "phone", "email", {"name": "score", "type": "float", "min": 0, "max": 100}]
}
```
### 嵌套对象
```json
{
"count": 2,
"fields": [
{"name": "buyer", "type": "user"},
{"name": "order_info", "type": "order"}
]
}
```
按字段列表或预设 schema 批量生成模拟测试数据,适用于前端联调、接口 Mock、演示环境等场景。
## 请求参数
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| count | int | 否 | 生成条数,默认 1,最大 100 |
| schema | string | 否 | 预设模板:`user`(用户)、`order`(订单)、`product`(商品)、`address`(地址)、`article`(文章)、`comment`(评论) |
| fields | array | 否 | 自定义字段列表;与 schema 同时传入时会合并,同名字段以 fields 为准 |
### fields 写法
- 字符串:`"phone"` — 按字段名自动推断类型
- 对象:`{"name":"age","type":"int","min":18,"max":60}` — 显式指定类型
- 嵌套:`{"name":"buyer","type":"user"}` — 生成完整用户对象
## 常用 field type
`string` `int` `float` `bool` `text` `enum` `name` `phone` `email` `idcard` `address` `date` `datetime` `url` `uuid` `ip` `avatar` `money` `order_no` `product_name` `user` `order` `product` `article` `comment`
## 示例
### 预设用户模板
```json
{"count": 10, "schema": "user"}
```
### 预设订单模板
```json
{"count": 5, "schema": "order"}
```
### 自定义字段
```json
{
"count": 3,
"fields": ["name", "phone", "email", {"name": "score", "type": "float", "min": 0, "max": 100}]
}
```
### 嵌套对象
```json
{
"count": 2,
"fields": [
{"name": "buyer", "type": "user"},
{"name": "order_info", "type": "order"}
]
}
```
调用地址:https://api.ynlskj.com.cn/gateway/mockdata
请求方法:POST
在其他地方怎么调用
- 请求地址用上面的调用地址,把 JSON 放在请求体里
- 方法用
POST - API Key 只能放在请求头
X-API-Key,不要写进网址,也不要写进 Query 框 - Key 在「个人中心 → API Key」里复制,登录后会自动填入你自己的 Key
参数说明
| 参数 | 位置 | 必填 | 说明 |
|---|---|---|---|
count | Query | 示例值:3 | |
schema | Query | 示例值:user | |
fields | Query | 示例值: | |
X-API-Key | Header | 是 | 你的 API Key |
返回说明
| 字段 | 说明 |
|---|---|
ret | ok 成功,err 失败 |
data | 接口返回数据 |
msg | 本站提示,如「次数充足,剩余 99 次」或「次数不足,剩余 0 次」 |
remain_quota | 本次调用后的剩余次数 |
可直接复制的代码
未登录时示例只显示「你的密钥」。登录后会自动填入你自己的 Key,不会展示别人的。
<?php
$ch = curl_init('https://api.ynlskj.com.cn/gateway/mockdata');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['X-API-Key: 你的密钥', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{
"count": 3,
"schema": "user",
"fields": [
{
"name": "vip_level",
"type": "enum",
"values": [
"普通",
"黄金",
"钻石"
]
}
]
}',
]);
echo curl_exec($ch);
请求参数演示
{
"count": 3,
"schema": "user",
"fields": [
{"name": "vip_level", "type": "enum", "values": ["普通", "黄金", "钻石"]}
]
}
响应演示
{
"ret": "ok",
"data": {
"count": 3,
"schema": "user",
"fields": ["id", "name", "phone", "email", "gender", "age", "idcard", "address", "avatar", "created_at", "vip_level"],
"list": [
{
"id": 12345678,
"name": "张伟",
"phone": "13812345678",
"email": "zhangwei@example.com",
"gender": "男",
"age": 28,
"idcard": "530102199001011234",
"address": "云南省昆明市五华区人民路88号",
"avatar": "https://picsum.photos/seed/12345/200/200",
"created_at": "2024-06-15 10:30:00",
"vip_level": "黄金"
}
],
"types": {
"schema": ["user", "order", "product", "address", "article", "comment"],
"field_type": ["string", "int", "float", "bool", "text", "enum", "name", "phone", "email", "user", "order", "product", "article", "comment"]
}
}
}