---
title: API 規劃發想 - 行雲知識王
tags: 行雲知識王, 寒訓
---
[< 回首頁](/TTNiCAWfRz6aGHQfw-Zrrw)
# 參考資料
- https://app.swaggerhub.com/apis/moontai0724/hackathon/0.0.1
# 查看資料庫
- URL: http://120.110.114.73:23080/phpmyadmin
- Account: app
- Password: app
# 文件圖示說明
:::danger
:accept: <- 若看見此圖示,代表 API 已經上線並經過測試。
:closed_lock_with_key: <- 看見此圖示,就是需要登入才能使用的 API
:::
# :closed_lock_with_key: 要求登入的 API
:::warning
## session_id
當沒有 cookie 使用時,可以在 post 參數中加入 session_id 來登入。
## 當沒有登入時,API 會回傳以下錯誤
```json=
{
"code": 0,
"message": "Unknown error occurred, or not logged in.",
"data": []
}
```
註:若發生未知錯誤,也會回傳此錯誤。
:::
# 會員系統 規劃者/柏瑄 製作者/柏瑄
- :accept: 登入: http://120.110.114.73:23080/index.php/api/User/login
:::spoiler
- parameters:
- account: 帳號
- password: 密碼
- response
- success: 登入成功
```json=
{
"code": 1,
"message": "Login success.",
"data": {
"session_id": "grhch426cc3t8sdfhulga8tggsj0ao3k"
}
}
```
- fail: 帳號或密碼錯誤
```json=
{
"code": 0,
"message": "Login failed, account or password incorrect.",
"data": []
}
```
:::
- :closed_lock_with_key: :accept: 登出: http://120.110.114.73:23080/index.php/api/User/logout
:::spoiler
- parameters: []
- response
- success: 登出成功
```json=
{
"code": 1,
"message": "logout success.",
"data": []
}
```
:::
- :accept: 註冊:
http://120.110.114.73:23080/index.php/api/User/register
:::spoiler
- parameters:
- name: 暱稱
- account: 帳號
- password: 密碼
- mail: 電子郵件
- response
- success: 註冊成功
```json=
{
"code": 1,
"message": "Registration success.",
"data": []
}
```
- fail: 帳號已被註冊
```json=
{
"code": 0,
"message": "Invalid input",
"data": [
"account": "Account is already used."
]
}
```
- fail: 電子郵件已被註冊
```json=
{
"code": 0,
"message": "Invalid input",
"data": [
"mail": "Mail is already used."
]
}
```
- fail: 欄位不能為空
```json=
{
"code": 0,
"message": "Invalid input",
"data": [
"account": "Field cannot be empty.",
"password": "Field cannot be empty."
]
}
```
- fail: 格式錯誤
```json=
{
"code": 0,
"message": "Invalid input.",
"data": [
"account": "Wrong format.",
"mail": "Wrong format."
]
}
```
:::
<!-- - 忘記密碼 -->
- :closed_lock_with_key: :accept: 修改密碼
http://120.110.114.73:23080/index.php/api/User/modifypassword
:::spoiler
- parameters:
- password: 密碼
- newPassword: 新密碼
- response
- success: 修改成功
```json=
{
"code": 1,
"message": "Modify success.",
"data": []
}
```
- fail: 舊密碼不正確
```json=
{
"code": 0,
"message": "Old password is wrong.",
"data": []
}
```
:::
- :closed_lock_with_key: :accept: 修改暱稱
http://120.110.114.73:23080/index.php/api/User/modifyName
:::spoiler
- paramters:
- newName: 新暱稱
- response:
- success: 修改成功
```json
{
"code": 1,
"message": "Modify success."
}
```
- fail: 欄位不能為空
```json
{
"code": 0,
"message": "Field cannot be empty."
}
```
:::
- :closed_lock_with_key: 更換頭貼
- :closed_lock_with_key: :accept: 獲取個人資訊
http://120.110.114.73:23080/index.php/api/User/getUserInformation
:::spoiler
- paramters:
- response:
- success: 獲取成功
```json
{
code: 1,
message: "Success.",
"data": {
"name": "222222",
"mail": "111@gmail.com",
"account": "11111",
"total_answered_amount": "0",
"total_correct_amount": "0",
"photo_path": null
}
}
```
:::
<!-- - 登入天數 -->
# 歷史紀錄 規劃者/彬瑞 製作者/
- :closed_lock_with_key: :accept: 獲取全部歷史紀錄:
http://120.110.114.73:23080/index.php/api/History/getList
:::spoiler
- parameters: []
- response
- success: 成功
```json=
{
"code": 1,
"message": "success",
"data": [
{
"id": "1",
"user_id": "1",
"score": "100",
"average_correct_rate": "0",
"average_time_used": "5",
"time": "2020-02-26 15:08:29"
}
]
}
```
- fail: 錯誤
```json=
{
"code": 0,
"message": "No data found.",
"data": []
}
```
:::
- :closed_lock_with_key: :accept: 獲取紀錄的詳細資訊
http://120.110.114.73:23080/index.php/api/History/getDetail
:::warning
# 備註
## selected_option
若此選項為 0,則為使用使用者沒有回答這個問題
1、2、3、4 分別代表選擇了 option_1、option_2、option_3、option_4
## correctness
0 為 錯誤,1 為正確
:::
:::spoiler
- parameters:
- history_id
- response
- success: 成功
```json=
{
"code": 1,
"message": "Success.",
"data": [
{
"history_id": "5",
"question_id": "14",
"selected_option": "0",
"correctness": "0",
"time_used": "0",
"score": "0",
"time": "2020-02-27 15:39:20",
"author_id": "1",
"category_id": "2",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"answer": "3"
}
]
}
```
- fail: 錯誤
```json=
{
"code": 0,
"message": "No data found.",
"data": []
}
```
:::
# 題目 規劃者/柏瑄 製作者/彬瑞、泓亦
- :closed_lock_with_key: :accept: 獲取題目類別: http://120.110.114.73:23080/index.php/api/Category/getAllCategory
:::spoiler
- parameters: []
- response:
- success: 獲取成功
```json=
{
"code": 1,
"message": "Success.",
"data": [
{
"id": "1",
"abstract_category_id": "1",
"difficulty": "易",
"question_amount": "0",
"title": "SQL",
"group_title": "1",
"group_image_path": null,
"group_id": "1"
},
{
"id": "2",
"abstract_category_id": "1",
"difficulty": "中",
"question_amount": "1",
"title": "SQL",
"group_title": "1",
"group_image_path": null,
"group_id": "1"
},
{
"id": "3",
"abstract_category_id": "1",
"difficulty": "難",
"question_amount": "0",
"title": "SQL",
"group_title": "1",
"group_image_path": null,
"group_id": "1"
},
{
"id": "4",
"abstract_category_id": "2",
"difficulty": "易",
"question_amount": "0",
"title": "ListView",
"group_title": "2",
"group_image_path": null,
"group_id": "2"
},
{
"id": "5",
"abstract_category_id": "2",
"difficulty": "中",
"question_amount": "0",
"title": "ListView",
"group_title": "2",
"group_image_path": null,
"group_id": "2"
},
...
]
}
```
:::
<!-- - 題目難易度 -->
- :closed_lock_with_key: :accept: 獲取題目: http://120.110.114.73:23080/index.php/api/Question/startGame
:::spoiler
- parameters:
- category_id: 類別id
- response
- success: 如果題目不足十題
```json=
{
"code": 1,
"message": "Success.",
"data": {
"history_id": 4,
"questions": [
{
"id": "1",
"category_id": "3",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
},
{
"id": "2",
"category_id": "3",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
},
{
"id": "3",
"category_id": "3",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
}
...
]
}
}
```
- sucess: 如果題目完整
```json=
{
"code": 1,
"message": "Success.",
"data": {
"history_id": 5,
"questions": [
{
"id": "51",
"category_id": "2",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
},
{
"id": "22",
"category_id": "2",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
},
{
"id": "34",
"category_id": "2",
"title": "請問如果想要撈出 app 資料庫中 user 資料表的 id, name, account 欄位,如何下才是正確的?",
"option_1": "SELECT * FROM user",
"option_2": "SELECT id, name, account FROM app",
"option_3": "SELECT id, name, account FROM user",
"option_4": "SELECT * FROM app",
"time_limit": "15"
}
...
}
```
- fail: 建立歷史紀錄失敗
```json=
{
"code": 0,
"message": "Error, create history failed.",
"data": []
}
```
- fail: 找不到題目
```json=
{
"code": 0,
"message": "Error, no question found.",
"data": []
}
```
- fail: 沒有提供 Category ID
```json=
{
"code": 0,
"message": "No category id given.",
"data": []
}
```
:::
- :closed_lock_with_key: 回答題目
:::spoiler
- parameter
- history_id: 歷史紀錄流水號
- question_id: 問題流水號
- selected_option: 選了哪個選項 (1, 2, 3, 4)
- time_used: 做題使用幾秒
- response
- success
```json=
{
"code": 1,
"message": "Update success.",
"data": {
"id": "7",
"user_id": "1",
"score": "293",
"total_answered_amount": "1",
"total_correct_amount": "1",
"total_time_limit": "15",
"total_time_used": "8",
"average_correct_rate": "0",
"average_time_used": "0",
"time": "2020-02-27 16:18:29"
}
}
```
- failed: 沒有相符的紀錄
```json=
{
"code": 0,
"message": "Did not found any history detail with provided history_id and question_id.",
"data": []
}
```
- failed: 選項無效
```json=
{
"code": 0,
"message": "Provided selected_option is not valid.",
"data": []
}
```
:::
<!-- - 線上對戰 -->
# 排行榜 規劃者/柏瑄 製作者/嘉洋
- :closed_lock_with_key: 獲取排行榜
:::spoiler
- parameter
- selectedCatagories : 選擇類別
- type(array)
- response
- sucess 成功
```json=
{
"code": 1,
"message": "Success.",
"data": [
{
"user_id": "7",
"name": "kk"
"score": "1200",
},
{
"user_id": "1",
"name": "管理員",
"score": "500",
},
{
"user_id": "23",
"name": "wqewqe",
"score": "500",
},
{
"user_id": "15",
"name": "kkf",
"score": "100",
}
]
}
```
- fail 無任何使用者排行紀錄
```json=
{
"code": 0,
"message": ":Lack of class score.",
"data": []
}
```
:::
<!-- - 勝率制 -->
# 大家的規劃文件
- [彬瑞](/eVH3h8DHR8OEnTxVrqzMWg)
- [柏瑄](/zr8lF_gIQKK2A2WjfD7CFA)
- [泓亦](/LGAQp5ZCTN6JS6FAgDgrgw)
<style>
details {
border: 1px solid gray;
border-radius: 10px;
padding: 15px;
margin: 5px;
box-shadow: 5px 5px lightgray;
}
details summary:after {
content: "詳細資訊";
}
</style>