批量创建答题卡
更新时间:2022-09-02 18:08:07
接口URL
https://api.polyv.net/live/v3/channel/question/batch-save
接口说明
批量创建答题卡,创建一套直播频道答题卡模板与相对应的模板题目。
支持格式
JSON
请求方式
POST
请求参数
| 参数名 | 必选 | 类型及范围 | 说明 |
|---|---|---|---|
| appId | 是 | string | 从API设置中获取,在直播系统登记的appId |
| timestamp | 是 | long | 当前13位毫秒级时间戳,3分钟内有效 |
| sign | 是 | String | 签名,为32位大写的MD5值,生成签名的appSecret密钥作为通信数据安全的关键信息,严禁保存在客户端直接使用,所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据【详见签名生成规则】 |
| channelId | 是 | string | 频道号 |
| name | 否 | string | 模板名称,不传不会生成答题卡模板数据 |
| status | 否 | string | 模板状态unused:上传成功,used:使用中 |
| questions[].identifyId | 否 | string | 记录题目ID,接口成功后会返回这个id对应系统的questionId |
| questions[].name | 是 | string | 题目名称 |
| questions[].type | 是 | string | 题目类型R:单选,C:多选,S:评分 |
| questions[].option1 | 否 | string | 选项1,option不能同时为空,有数据必须连续 |
| questions[].option2 | 否 | string | 选项2,option不能同时为空,有数据必须连续 |
| questions[].option3 | 否 | string | 选项3,option不能同时为空,有数据必须连续 |
| questions[].option4 | 否 | string | 选项4,option不能同时为空,有数据必须连续 |
| questions[].option5 | 否 | string | 选项5,option不能同时为空,有数据必须连续 |
| questions[].answer | 否 | string | 当questions[].type 是评分时,非必填,单选,多选答案,比如多选ABC,单选A(单选不能有两个) |
| questions[].tips1 | 否 | string | 当questions[].type是评分,传入option1相应的值 ,也就是分值提示 |
| questions[].tips2 | 否 | string | 当questions[].type是评分,传入option2相应的值 ,也就是分值提示 |
| questions[].tips3 | 否 | string | 当questions[].type是评分,传入option3相应的值 ,也就是分值提示 |
| questions[].tips4 | 否 | string | 当questions[].type是评分,传入option4相应的值 ,也就是分值提示 |
| questions[].tips5 | 否 | string | 当questions[].type是评分,传入option5相应的值 ,也就是分值提示 |
注:这里的channelId,appId,timestamp,sign必须通过url传参,json数据通过请求体传参,如: https://api.polyv.net/live/v3/channel/questionnaire/add-edit-questionnaire?channelId={{channelId}}&appId={{appId}}×tamp={{timestamp}}&sign={{sign}}
body入参示例
{
"name":"nana",
"questions": [
{
"identifyId": "123",
"name":"第一题",
"type":"R",
"option1": "哈哈",
"option2": "测试",
"answer":"A"
}
]
}
返回结果
// 成功结果
{
"code": 200,
"status": "success",
"message": "success",
"data": {
"templateId": "xxxxxx",
"questionKey": {
"123": "xxxxx",
"identifyId2": "questionId2"
}
}
}
失败返回json
// 未输入appId
{
"code": 400,
"status": "error",
"message": "appId is required.",
"data": ""
}
// appId不正确
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
//时间戳错误
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
// 签名错误
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
// 频道号格式错误
{
"code": 400,
"status": "error",
"message": "param is not digit: dsadasd",
"data": ""
}
响应参数说明
| 字段 | 说明 | 类型 |
|---|---|---|
| code | 响应码 | int32 |
| status | 响应状态:success/error/fail | string |
| message | 错误信息说明 | string |
| data | 响应数据 | object |
| data.templateId | 模板templateId | string |
| data.questionKey | 模板题目,参数中的identifyId对应系统中的提问主键questionId,是一个对象,key-value形式,如果不需要对应题目与系统题目questionId,可以忽略该参数 | Object |
响应错误说明
| 错误代码 | message | 说明 |
|---|---|---|
| 400 | appId is required. | 未输入appId |
| 400 | application not found. | appId不正确 |
| 400 | invalid timestamp. | 时间戳错误 |
| 400 | invalid signature. | 签名错误 |
| 400 | param is not digit: dsadasd | 频道号格式错误 |
| 400 | type illegal. type T. | 题目类型错误 |
| 400 | xxxx name is blank | identifyId的题目标题为空 |
| 400 | xxxx answer is blank | identifyId的题目答案为空 |
| 400 | xxxx options are all blank | identifyId的所有选项为空 |
| 400 | xxxx options are discontinuous | identifyId选项不连续 |
| 400 | xxxx answer's option is empty | identifyId题目对应答案为空 |
| 400 | xxxx illegal answer | identifyId非法答案 |
PHP请求示例
<?php
$appId="xxxxxxxxxxx";
$timestamp=time()*1000;
$url = 'https://api.polyv.net/live/v3/channel/question/batch-save?';
$header = array('application/json');
$data = array(
'appId' => $appId,
'timestamp' => $timestamp,
'channelId' => 206204
);
$data["sign"]=$hash;
$json = '{
"name":"nana",
"questions": [
{
"identifyId": "123",
"name":"第一题",
"type":"R",
"option1": "哈哈",
"option2": "测试",
"answer":"A"
}
]
}'
// 请求接口
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$sResult = curl_exec($ch);
if($sError=curl_error($ch)){
die($sError);
}
curl_close($ch);
//打印获得的数据
print_r($sResult);
?>
