corgi/doc/partner.md

331 lines
8.8 KiB
Markdown
Raw 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.

# 金蚕游戏管理后台相关说明
## 修改记录
### 20210620
第一版
## 说明
1. 所有接口均使用POST提交数据, Content-Type为application/json
例: curl
```shell
curl --location --request POST 'https://puzzle-admin.kingsome.cn/api/partner/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "北京金蚕网络科技有限公司",
"sid": "123456789j",
"timestamp": 1624333003587,
"sign": "c4cfdad34de8fe8787cb8c74abe7a8692e11725ff582271b57ff1ebaa00b488a",
"logo": "https://resource.kingsome.cn/test60d07f3fb40504740fdccb6e.png"
}'
```
例: php
```php
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('http://127.0.0.1:2900/api/partner/login');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Content-Type' => 'application/json'
));
$request->setBody('{\n "name": "北京金蚕网络科技有限公司",\n "sid": "123456789j",\n "timestamp": 1624333003587,\n "sign": "c4cfdad34de8fe8787cb8c74abe7a8692e11725ff582271b57ff1ebaa00b488a",\n "logo": "https://resource.kingsome.cn/test60d07f3fb40504740fdccb6e.png"\n}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
```
2. 所有请求参数中带*号的不能为空
3. 接口签名字段说明
```
# 1. 将参与签名的参数按照key=value的格式并按照参数名ASCII字典序升序排序, 例如:
var signStr = 'name=一品漫城&sid=65AB7856FE&timestamp=1624332778169'
# 2. 把我们提供的 secretKey(37284c327e10d8b73cf4325f33a3de4b34032e3e) 作为key, 使用HMAC-SHA256得到签名
var sign = HmacSHA256(signStr, secretKey)
```
4. 如无特殊说明, 所有接口返回json, 顶级结构如下, 接口Response的数据结构说明只包含data部分
``` JSON
{
"code": 0, //0:成功 2: 缺少必要参数(accountid, sessionid) 4: 帐号被封, 5: 帐号未找到 100: 所有未定义的错误
"msg": "", //错误描述, 一般在code=0时, 该字段为空
"data": {}, // 数据
}
```
4. 页面列表
> 所有的页面均可单独调用, url: https://puzzle-admin.kingsome.cn/页面url?token=token&mini=1
> token为 1号接口获取
| 页面名称 | 页面url |
| ---------- | ----------------- |
| 店铺管理员 | /#/shop/shopadmin |
| 游戏设置 | /#/shop/setting |
| 活动列表 | /#/shop/activity_list |
| 挑战活动列表 | /#/shop/exam_list |
| 抽奖转盘 | /#/shop/lottery_setting |
| 分享设置 | /#/shop/share_setting |
| 优惠券设置 | /#/marketing/coupon |
| 题库设置 | /#/question/setting |
| 自定义题库 | /#/question/shoppuzzles |
| 邮件 | 暂不开放 |
| 公告 | 暂不开放 |
## 接口列表
### 1. 获取token
> 这里获取的token用于调用页面时拼接url
1. Method: POST
2. URI: /api/partner/login
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| name | *店铺完整名称 |
| sname | 店铺显示的短名称(如果该字段为空的话, 取name字段) |
| sid | *唯一的店铺id, 接口根据此字段判断该次上报是否是同一家店铺 |
| logo | 店铺的logo, 一个可以外网访问的url地址 |
| timestamp | *10或13位均可 |
| sign | *签名 |
> 签名字段: name, sid, timestamp
3. Response: JSON
```js
{
token: '1231231aasa'
}
```
### 2. 查询店铺信息
1. Method: POST
2. URI: /api/partner/shop/info
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | *店铺id, 1号接口里上传的sid |
| timestamp | *10或13位均可 |
| sign | *签名 |
> 签名字段: shop, timestamp
3. Response: JSON
```js
{
"_id": "店铺唯一id",
"sid": "店铺的短id",
"partnerId": "你们提供的店铺唯一id",
"name": "店铺名",
"showName": "店铺显示名",
"logo": "店铺logo的url地址",
"createdAt": "店铺创建时间",
"publish": true // 是否已发布
}
```
### 3. 导入题库
1. Method: POST
2. URI: /api/partner/puzzle/import
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop| *店铺id |
| datas| *数据列表, 结构如下 |
| timestamp | *10或13位均可 |
| sign| *签名 |
> 签名字段: shop, timestamp
datas的数据示例
```json
{
"question": "烊行的“烊”字怎么念", // 题目
"a1": "羊", // 正确答案
"a2": "火", // 混淆答案1
"a3": "样", // 混淆答案2
"a4": "你猜我猜不猜8964", // 混淆答案3
"type": 1, // 题目类型, 1: 普通的题目, 3: 问卷
"groups": [ // 题目标签, 可当分类来用
"问卷"
]
}
```
3. Response: JSON
```js
{
"insert": 1, // 插入数量
"update": 0, // 更新同名题目数量
"skip": 0, // skip数量
"batch": 1624346272949 // 本次导入的批次
}
```
### 4. 查询题库审核结果
1. Method: POST
2. URI: /api/partner/puzzle/status
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | 店铺id |
| batch | *导入时返回的批次 |
| timestamp | *10或13位均可 |
| sign| *签名 |
> 签名字段: shop, batch, timestamp
3. Response: JSON
```js
[ // 题目审核状态数组
{
"id": "60d18ea07938dbda87d2e346", // 题目唯一id
"q": "烊行的“烊”字怎么念", // 题目
"status": 0 // 0: 未审核, 1: 审核通过, -1: 审核未通过
}
]
```
### 5. 挑战列表
1. Method: POST
2. URI: /api/partner/exams
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | 店铺id |
| timestamp | *10或13位均可 |
| sign| *签名 |
| start| 跳过的记录条数 |
| limit|读取记录条数 |
| key| 查询的关键字 |
> 签名字段: shop, timestamp
3. Response: JSON
```js
{
"total": 1, // 总数
"start": 0, // 当前跳过的记录条数
"limit": 10, // 读取记录条数
"records": [
{
"_id": "60b4d97545f1f1530f2404de", // 挑战记录id
"name": "test", // 挑战名称
"createdAt": "2021-05-31T12:41:25.864Z", // 记录创建时间
"active": true, // 是否启用
"beginTime": 0, // 开始时间
"endTime": 1924963201000, // 结束时间
"source": 3, // 题目来源,0: 系统题目, 1: 自定义, 2: 店铺自定义题库, 3: 混合题库
"qcount": 2, // 每次挑战的题目数量
"timeone": 50 // 每道题目回答的最长时间(秒)
}
]
}
```
### 6. 挑战记录导出
1. Method: POST
2. URI: /api/partner/historys
3. HOST: https://puzzle-admin.kingsome.cn
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | *店铺id |
| exam| 挑战活动id |
| timestamp | *10或13位均可 |
| sign| *签名 |
| start| 跳过的记录条数 |
| limit|读取记录条数 |
> 签名字段: shop, timestamp
3. Response: JSON
```js
{
"total": 6,
"start": 0,
"limit": 10,
"records": [{ // 记录数组
"_id": "60b4d97545f1f1530f2404df", // 记录唯一id
"status": 1, // 记录状态, 0: 未开始, 1: 进行中, 9: 结束
"createdAt": "2021-05-31T12:45:21.395Z", // 答题开始时间
"type": 2, // 记录类型, 2: 挑战活动
"activityId": "60b4d97545f1f1530f2404de", // 挑战活动id
"qcount": 10, // 当前局一共多少题
"accountId": "1111", // 玩家帐号id
"questions": [{ // 当前局的所有题目
"title": "1126", // 题目标题
"answers": [ // 答案数组, 第一个是正确答案
"你好啊啊啊",
"b",
"246"
],
"answer": 0 // 玩家回答的答案, -1为未回答
}],
"nickname": "", // 玩家昵称
"score": 300.57172, // 得分
"count": 2 // 玩家已回答题目数量
}]
}
```