保利威文档中心

幫助中心

建立角色

更新時間:2023-06-26 17:23:32

舊版介面位址建立單一角色(舊版)

介面說明

1、创建频道的助教或嘉宾角色
   助教:使用助教管理后台,能够观看直播、参与互动、进行聊天室管理,发送图文直播,监控直播等操作
   嘉宾:讲师和嘉宾可同时讲一堂课,支持连麦互动
2、(channelId, timestamp, appId)参与sign签名,并和sign一起通过url传递,请求体参数不参与签名,通过post请求体传递【请设置请求头contentType:application/json】
3、接口支持https协议

介面URL

http://api.polyv.net/live/v4/channel/account/create

線上API呼叫

請求方式

POST

介面限制

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

2、不能同時設定監播和翻頁以及線上列表權限

3、每個直播頻道最多可以建立150個助教,嘉賓最大數量為16

4、建立嘉賓需要設定頻道連麥人數,開啟連麥功能

請求參數說明

參數名 必選 類型 說明
appId true String 帳號appId【詳見取得金鑰
timestamp true Long 目前13位毫秒級時間戳,3分鐘內有效
sign true String 簽名,為32位大寫的MD5值,產生簽名的appSecret金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則
channelId true String 頻道ID

請求體參數說明

參數名 必選 類型 說明
role true String 角色
Assistant:助教
Guest:嘉賓
actor false String 頭銜,長度1~10位,助教預設為助教
nickName false String 暱稱,長度1~15位,預設隨機產生暱稱
avatar false String 頭像,預設初始頭像(JPG、PNG格式圖片)
passwd false String 角色密碼,長度6~16位,預設隨機產生密碼
purviewList false Array 權限【詳見purviewList欄位說明

purviewList參數說明

參數名 必選 類型 說明
code true String 權限
chatListEnabled:線上列表(僅支援助教)
pageTurnEnabled:翻頁(僅支援助教,且僅能設定一個助教有翻頁權限)
monitorEnabled:監播(僅支援助教,且僅能設定一個助教有監播權限)
chatAuditEnabled:聊天審核(僅支援助教)
enabled true String 開關
Y:開啟
N:關閉

範例

http://api.polyv.net/live/v4/channel/account/create?appId=frlr1zazn3&sign=02BBB29D3C5FE62157E6E0ED2AB5D844&channelId=2824409&timestamp=1648778488853

請求體json參數:

{
    "actor": "助教sadboy",
    "role": "Assistant",
    "passwd": "test123456",
    "nickName": "昵称sadboy",
    "avatar": "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png",
    "purviewList": [
        {
            "code": "chatListEnabled",
            "enabled": "N"
        },
        {
            "code": "monitorEnabled",
            "enabled": "Y"
        }]
}

回應參數說明

參數名 類型 說明
code Integer 狀態碼,與 http 狀態碼相同,用於確定基本的回應狀態
status String 回應結果,由業務決定,成功回傳success,失敗回傳error
success Boolean 是否成功回應
requestId String 請求ID,每次請求產生的唯一的 UUID,僅可用於排查、除錯,不應該和業務掛鉤
error Object 狀態碼非200時的錯誤資訊【詳見Error欄位說明
data Object 【詳見data欄位說明

Error參數說明

參數名 類型 說明
code Integer 錯誤代碼,用於確定具體的錯誤原因
desc String 錯誤描述,與 error.code 對應

data參數說明

參數名 類型 說明
account String 助教/嘉賓帳號
userId String 使用者ID
channelId Integer 頻道號
passwd String 角色密碼
nickname String 角色名稱
stream String 角色串流名稱,單獨使用無效
status String 角色狀態
Y:開啟
N:關閉
createdTime Long 建立角色時間,13位毫秒級時間戳
lastModified Long 角色最後修改時間,13位毫秒級時間戳
sort Integer 頻道角色序號
avatar String 角色頭像
actor String 角色頭銜
role String 角色
Assistant:助教
Guest:嘉賓
monitorEnabled String 監播權限
Y:開啟
N:關閉
pageTurnEnabled String 翻頁權限
Y:開啟
N:關閉
chatListEnabled String 線上列表權限
Y:開啟
N:關閉
chatAuditEnabled String 聊天審核權限
Y:開啟
N:關閉

Java請求範例

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

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

private static final Logger log = LoggerFactory.getLogger(ChannelOperateTest.class);
/**
 * 创建角色
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testAddChannelAccount() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
    
    //业务参数
    String url = "http://api.polyv.net/live/v4/channel/account/create";
    String channelId = "2824409";
    String role = "Assistant";
    String actor = "助教sadboy";
    String nickName = "昵称sadboy";
    String avatar = "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png";
    String passwd = "test123456";
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
    requestMap.put("channelId", channelId);
    
    List<Map<String, String>> purviewList = new ArrayList<>();
    Map<String, String> purviewMap1 = new HashMap<>();
    purviewMap1.put("code", "chatListEnabled");
    purviewMap1.put("enabled", "N");
    purviewList.add(purviewMap1);
    Map<String, String> purviewMap2 = new HashMap<>();
    purviewMap2.put("code", "monitorEnabled");
    purviewMap2.put("enabled", "Y");
    purviewList.add(purviewMap2);
    
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("role", role);
    jsonMap.put("actor", actor);
    jsonMap.put("nickName", nickName);
    jsonMap.put("avatar", avatar);
    jsonMap.put("passwd", passwd);
    jsonMap.put("purviewList", purviewList);
    
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    url = HttpUtil.appendUrl(url, requestMap);
    String response = HttpUtil.postJsonBody(url, JSON.toJSONString(jsonMap), null);
    log.info("测试创建角色成功:{}", response);
    //do somethings
    
}

回應範例

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

成功範例

{
    "code": 200,
    "status": "success",
    "requestId": "86d11d4aa00b49f5993ac0891e670470.65.16487784917647731",
    "data":
    {
        "account": "0062824409",
        "userId": "1b448be323",
        "channelId": 2824409,
        "passwd": "test123456",
        "nickname": "昵称sadboy",
        "stream": "l1fs56ih",
        "status": "Y",
        "createdTime": 1648778491961,
        "lastModified": 1648778491961,
        "sort": 6,
        "avatar": "//liveimages.videocc.net/uploaded/images/2022/04/g8fydrvq5l.png",
        "actor": "助教sadboy",
        "pageTurnEnabled": null,
        "notifyEnabled": "Y",
        "checkinEnabled": "Y",
        "voteEnabled": "Y",
        "lotteryEnabled": "Y",
        "chatListEnabled": "N",
        "chatAuditEnabled": null,
        "monitorEnabled": "Y",
        "roundTourEnabled": null,
        "watchLockEnabled": null,
        "role": "Assistant"
    },
    "success": true
}

異常範例

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
联系客服,在线咨询