接口约定
- 使用https
- restful风格
- 用户端:https://{域名}/api/{接口版本号}/{resource}/{resource_id}/{sub_resource}/{sub_resource_id}/{action}?{query_string}
- 管理端:https://{域名}/admin/api/{接口版本号}/{resource}/{resource_id}/{sub_resource}/{sub_resource_id}/{action}?{query_string}
- 测试环境域名babieta.xivan.cn
- 正式环境域名待定
- 公共参数放在header,如userid,session_key,unionid,version等
- resource: studies
接口
gcid算法
def gcid_hash_file(path):
h = hashlib.sha1()
size = os.path.getsize(path)
psize = 0x40000
while size / psize > 0x200 and psize < 0x200000:
psize = psize << 1
with open(path, 'rb') as stream:
data = stream.read(psize)
while data:
h.update(hashlib.sha1(data).digest())
data = stream.read(psize)
return h.hexdigest()
GET /studies/auth/qiniu/tokens/<gcid>
name |
cname |
type |
Description |
用途 |
|
|
获取七牛token |
版本号 |
|
|
v1.0 |
gcid |
|
|
gcid |
例
curl -XGET https://babieta.xivan.cn/api/v1.0/auth/qiniu/tokens/abc
返回数据:
name |
cname |
type |
Description |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |
token |
|
string |
上传文件凭证(5分钟有效) |
key |
|
string |
上传文件key |
例
{
"code"0,
"msg":"",
"token":"xxxx",
"key":"yyyy"
}
GET /studies/{studies_id}/contents
name |
cname |
type |
Description |
用途 |
|
|
获取测试题 |
版本号 |
|
|
v1.0 |
studies_id |
|
|
express(表达训练)/soak(浸泡训练)/communication(交流训练) |
请求数据:
query_string 参数/可选参数
name |
cname |
type |
Description |
limit |
数目 |
int |
获取数量, 默认1 |
level |
等级 |
int |
等级 |
flag |
标识 |
int |
默认0.获取需要练习的列表, 1.获取当天已完成的列表 |
例
curl -i "https://babieta.xivan.cn/api/v1.0/studies/express/contents?limit=1&level=3" -H "userid:oslC94mGqAAEz6iWhKhL9dEY5l3o" -H "token:25e8ba0469c6f1c0c6dcd4fe952b8e4e"
wx.request({
"url":"https://babieta.xivan.cn/api/v1.0/studies/express/contents?limit=1",
"method":"GET",
"success": res =>{
console.log(res)
},
"data":{limit:'1'},
"dataType":"json",
"header": { "content-type":"application/x-www-form-urlencoded",
"userid": "oslC94mGqAAEz6iWhKhL9dEY5l3o", "token":"25e8ba0469c6f1c0c6dcd4fe952b8e4e"},
"complete": res => {
console.log(res)
}
})
返回数据:
name |
cname |
type |
Description |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |
list |
|
array<object> |
测试题列表 |
list[].object |
|
array<object> |
测试题, 不同类型具体看下面定义 |
object->express_info(表达训练)
name |
cname |
type |
Description |
id |
|
int |
id |
title |
|
string |
标题 |
cover_url |
|
int |
单词图片 |
word_chi |
|
string |
单词中文 |
audio_text |
|
string |
语音文本 |
audio_url |
|
string |
语音播放url |
object->soak_info(浸泡训练)
name |
cname |
type |
Description |
id |
|
int |
id |
title |
|
string |
标题 |
cover_url |
|
int |
语音图片 |
audio_url |
|
string |
语音播放url |
object->communication_info(交流训练)
name |
cname |
type |
Description |
id |
|
int |
id |
title |
|
string |
标题 |
audio_text |
|
string |
语音文本 |
audio_url |
|
string |
语音播放url |
例
{
"msg": "",
"code": 0,
"list": [{"id":1, "cover_url":"111", "audio_url":"222", "word_chi":"111", "audio_text":"333"}]
}
POST /studies/{studies_id}/contents/{contents_id}/report
name |
cname |
type |
Description |
用途 |
|
|
上报修习结果 |
版本号 |
|
|
v1.0 |
studies_id |
|
|
express(表达训练)/soak(浸泡训练)/communication(交流训练) |
contents_id |
|
|
题目id |
请求数据:
body 参数/可选参数 (get)
name |
cname |
type |
Description |
duration |
时长 |
int |
时长(秒) |
status |
通过状态 |
int |
默认1 通过, 0:不通过 |
例
curl -XPOST -i "https://babieta.xivan.cn/admin/api/v1.0/studies/express/contents/3" -H "Content-Type:application/json" -d '{"duration":"100"}' -H "userid:oslC94mGqAAEz6iWhKhL9dEY5l3o" -H "token:25e8ba0469c6f1c0c6dcd4fe952b8e4e"
返回数据:
name |
cname |
type |
Description |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |
GET /studies/communication/contents/<content_id>/sound_records
name |
cname |
type |
Description |
用途 |
|
|
获取交流的录音列表 |
版本号 |
|
|
v1.0 |
content_id |
|
|
题目id |
请求数据:
query_string 参数/可选参数
name |
cname |
type |
Description |
limit |
数目 |
int |
获取数量, 默认10 |
例
curl -i "https://babieta.xivan.cn/api/v1.0/studies/communication/contents/4/sound_records?limit=10" -H "userid:oslC94mGqAAEz6iWhKhL9dEY5l3o" -H "token:25e8ba0469c6f1c0c6dcd4fe952b8e4e"
wx.request({
"url":"https://babieta.xivan.cn/api/v1.0/studies/communication/contents/4/sound_records",
"method":"GET",
"success": res =>{
console.log(res)
},
"data":{limit:'10'},
"dataType":"json",
"header": { "content-type":"application/x-www-form-urlencoded",
"userid": "oslC94mGqAAEz6iWhKhL9dEY5l3o", "token":"25e8ba0469c6f1c0c6dcd4fe952b8e4e"},
"complete": res => {
console.log(res)
}
})
返回数据:
name |
cname |
type |
Descriptio n |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |
list |
|
array<object> |
录音列表 |
list[].id |
|
int |
录音id |
list[].audio_url |
|
string |
录音链接 |
list[].audio_duration |
|
int |
录音时长(秒) |
list[].userid |
|
int |
录音人id |
list[].nickname |
|
int |
录音人名 |
list[].avatar_url |
|
int |
录音人头像 |
list[].praise_count |
|
int |
点赞数 |
list[].praise_flag |
|
int |
0:未点赞,1已点赞 |
例
{
"msg": "",
"code": 0,
"list": [{"id":1, "audio_duration":111, "audio_url":"222", "user_name":"111", "user_portrait":"333", "praise_count":3}]
}
GET /studies/communication/contents/<content_id>/history_sound_records
name |
cname |
type |
Description |
用途 |
|
|
获取交流的录音列表 |
版本号 |
|
|
v1.0 |
content_id |
|
|
题目id |
请求数据:
query_string 参数/可选参数
name |
cname |
type |
Description |
limit |
数目 |
int |
获取每个contentid对应的录音数量, 默认10 |
例
curl -i "https://babieta.xivan.cn/api/v1.0/studies/communication/contents/1,2,3,4/history_sound_records?limit=10" -H "userid:oslC94mGqAAEz6iWhKhL9dEY5l3o" -H "token:25e8ba0469c6f1c0c6dcd4fe952b8e4e"
wx.request({
"url":"https://babieta.xivan.cn/api/v1.0/studies/communication/contents/1,2,3,4/history_sound_records",
"method":"GET",
"success": res =>{
console.log(res)
},
"data":{limit:'10'},
"dataType":"json",
"header": { "content-type":"application/x-www-form-urlencoded",
"userid": "oslC94mGqAAEz6iWhKhL9dEY5l3o", "token":"25e8ba0469c6f1c0c6dcd4fe952b8e4e"},
"complete": res => {
console.log(res)
}
})
返回数据:
name |
cname |
type |
Descriptio n |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |
list |
|
array<object> |
问题列表 |
list[] |
|
array<object> |
录音列表 |
list[][].id |
|
int |
录音id |
list[][].audio_url |
|
string |
录音链接 |
list[][].audio_duration |
|
int |
录音时长(秒) |
list[][].userid |
|
int |
录音人id |
list[][].nickname |
|
int |
录音人名 |
list[][].avatar_url |
|
int |
录音人头像 |
list[][].praise_count |
|
int |
点赞数 |
例
{
"msg": "",
"code": 0,
"list": [[{"id":1, "audio_duration":111, "audio_url":"222", "user_name":"111", "user_portrait":"333", "praise_count":3}, ...], [], [], []]
}
POST /studies/communication/contents/<content_id>/sound_records/commit
name |
cname |
type |
Description |
用途 |
|
|
提交交流的录音 |
版本号 |
|
|
v1.0 |
content_id |
|
|
题目id |
请求数据:
body 参数/可选参数
name |
cname |
type |
Description |
audio_gcid |
gcid |
int |
音频内容md5后的字符串 |
audio_duration |
|
int |
录音时长(秒) |
返回数据:
name |
cname |
type |
Description |
code |
|
int |
返回码 0成功 非0失败 |
msg |
|
string |
错误信息 |