保利威文档中心

幫助中心

建立問答題目

更新時間:2022-09-02 18:08:07

介面描述

1、通过视频id创建视频的问答题目
2、接口支持https协议

介面URL

http://api.polyv.net/v2/video/save-video-exam

線上API呼叫

請求方式

POST

介面限制

1、介面同時支援HTTP、HTTPS,建議使用HTTPS以確保介面安全,介面呼叫有頻率限制,詳細請查看

請求參數說明

參數名 必填 類型 說明
userid true String 保利威點播帳戶ID,可參考【取得密鑰】取得,取得路徑:官網->登入->點播(API介面)
ptime true Long 目前時間的毫秒級時間戳記,3分鐘內有效
sign true String 簽名,為40位大寫的SHA1值,產生簽名的secretkey密鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則
vid true String 影片ID
examId false String 問答ID,為空時會新增一個題目。不為空時會修改已有的問答題目
showTime true Integer 問答出現的時間,單位:秒
question true String 問題描述
choices true String 問答選項,格式為JSON陣列物件,每個題目最多5個選項;例如:[{"index":0,"content":"a","isRight":true},{"index":2,"content":"b","isRight":false},{"index":3,"content":"c","isRight":false}]
canSkip false Boolean 設定是否可以跳過問答,預設不能跳過問答
true:表示可以跳過
false:表示不能跳過
explanationIfRight false String 回答正確後的解答詳情
showExplanationIfWrong false Boolean 回答錯誤後是否顯示解答詳情,預設為true
true:顯示
false:不顯示
explanationIfWrong false String 回答錯誤後的解答詳情
backTime false Integer 答錯後回退到第幾秒,-1代表不回退,預設為-1

範例

http://api.polyv.net/v2/video/save-video-exam

表單參數:

vid=1b448be3231ebf0005ec631a7e4247ee_1&question=%E6%B5%8B%E8%AF%95%E5%88%9B%E5%BB%BA%E9%97%AE%E7%AD%94%E9%A2%98%E7%9B%AE%EF%BC%9F&showTime=2&sign=27D7F36E628DE0E616DBE3C48A1AECEA090C2FCF&explanationIfRight=%E7%AD%94%E5%AF%B9%E5%95%A6&canSkip=false&choices=%5B%7B%22index%22%3A0%2C%22content%22%3A%22a%22%2C%22isRight%22%3Atrue%7D%2C%7B%22index%22%3A2%2C%22content%22%3A%22b%22%2C%22isRight%22%3Afalse%7D%2C%7B%22index%22%3A3%2C%22content%22%3A%22c%22%2C%22isRight%22%3Afalse%7D%5D&userid=1b448be323&ptime=1620286349810&explanationIfWrong=%E7%AD%94%E9%94%99%E4%BA%86&backTime=1

回應參數說明

參數名 類型 說明
code Integer 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明
status String 回應狀態文字資訊
message String 回應描述資訊,當code為400或500時,輔助描述錯誤原因
data Object 回應成功時返回examId,【詳見data欄位說明

data欄位說明

參數名 類型 說明
examId String 問答ID

Java請求範例

快速接入基礎程式碼請下載相關依賴原始碼點擊下載原始碼 ,下載後加入到自己的原始碼工程中即可。測試案例中的HttpUtil.java 和 VodSignUtil.java 都包含在下載檔案中。

強烈建議您使用點播Java SDK完成API的功能對接,點播Java SDK 對API呼叫邏輯、例外處理、資料簽名、HTTP請求執行緒池進行了統一封裝和最佳化。

private static final Logger log = LoggerFactory.getLogger(VodVideoManageManagementTest.class);
/**
 * 创建问答题目
 */
@Test
public void testAddQuiz() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = "http://api.polyv.net/v2/video/save-video-exam";
    String vid = "1b448be3231ebf0005ec631a7e4247ee_1";
    String showTime = "2";
    String question = "测试创建问答题目?";
    String choices = "[{\"index\":0,\"content\":\"a\",\"isRight\":true},{\"index\":2,\"content\":\"b\",\"isRight\":false},{\"index\":3,\"content\":\"c\",\"isRight\":false}]";
    String explanationIfRight = "答对啦";
    String explanationIfWrong = "答错了";
    String canSkip = "false";
    String backTime = "1";

    //调用参数
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("userid", userId);
    requestMap.put("ptime", ptime);
    requestMap.put("showTime", showTime);
    requestMap.put("vid", vid);
    requestMap.put("explanationIfRight", explanationIfRight);
    requestMap.put("question", question);
    requestMap.put("explanationIfWrong", explanationIfWrong);
    requestMap.put("canSkip", canSkip);
    requestMap.put("backTime", backTime);
    requestMap.put("choices", choices);
    requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
    String response =  HttpUtil.postFormBody(url,requestMap);
    log.debug("测试创建问答题目,{}", response);
    //do somethings
}

回應範例

系統全域錯誤說明詳見全域錯誤說明

成功範例

{
    "code":200,
    "status":"success",
    "message":"success",
    "data":{
        "examId":"1794097a449"
    }
}

異常範例

簽名不正確

{
"code":400,
"status":"error",
"message":"the sign is not right",
"data":""
}

時間戳記過期

{
"code":400,
"status":"error",
"message":"ptime is too old.",
"data":""
}

影片不存在

{
    "code": 400,
    "status": "error",
    "message": "video could not find by vid",
    "data": ""
}
联系客服,在线咨询