保利威文档中心

幫助中心

批量建立答題卡

更新時間: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}}&timestamp={{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);
?>
联系客服,在线咨询