保利威文档中心

幫助中心

查詢頻道聊天記錄

更新時間:2024-12-11 15:24:57

介面描述

1、通过频道号,查询一段时间内的聊天记录
2、接口支持https协议

介面URL

http://api.polyv.net/live/v3/channel/chat/get-history-page

線上API呼叫

請求方式

GET

介面限制

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

2、時間格式為yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss。如未提交具體時間,只提交了日期,開始時間預設為日期當天的 00:00:00,結束時間為日期當天的23:59:59

請求參數描述

參數名 必選 類型 說明
appId true String 帳號appId【詳見取得金鑰
timestamp true Long 當前13位毫秒級時間戳,3分鐘內有效
sign true String 簽名,為32位大寫的MD5值,產生簽名的appSecret金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則
startDay true String 聊天記錄的開始時間
格式為yyyy-MM-dd,例如:2021-03-01
或者格式為yyyy-MM-dd HH:mm:ss,例如:2021-03-01 16:30:12
endDay true String 聊天記錄的結束時間,要求同上
channelId true String 頻道號
page false Integer 取得第幾頁聊天記錄,預設為1
pageSize false Integer 每頁記錄數,預設為1000,最大為1000,大於1000將不會回傳contents資料
userType false String 使用者類型,可以選擇多個類型,用英文逗號隔開
slice:雲課堂學員
teacher:講師
guest:嘉賓
manager:管理員
assistant:助教
viewer:特邀觀眾
monitor:場監
attendee:研討會參與者
student:一般直播觀眾
status false String 聊天記錄審核狀態,預設pass:已審核
pass:已審核
censor:審核中和刪除
source false String 類型,不填預設公聊
extend:管理員私聊
roomId false String 如果有房間號,需要傳入房間號,預設不傳
hasTotal false String 是否回傳當前查詢總數,Y:是,N:否,預設為N
註:此參數可能會影響介面回應效能,若非強烈需求,建議不要傳此參數,可以根據回傳結果中的 contents 陣列長度來判斷是否還有下一頁

範例

http://api.polyv.net/live/v3/channel/chat/get-history-page?startDay=2020-03-10&appId=frlr1z1zn3&endDay=2021-03-10&sign=FD60256504E55BC4986B1BF9D207A997&pageSize=20&page=1&userType=&source=&channelId=1965681&roomId=&timestamp=1635478961187&status=

回應參數描述

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

data欄位說明

參數名 類型 說明
pageSize Integer 每頁資料大小
pageNumber Integer 當前的頁數
totalItems Integer 總的筆數, 僅當hasTotal為Y時有值,否則一直為0。
totalPages Integer 總頁數,限制同上
contents Object 查詢的結果列表【詳見Contents參數描述

contents欄位說明

參數名 類型 說明
id String 聊天訊息id
accountId String 帳號id
clientIP String 使用者ip(為了資料安全性,該資料將不再回傳)
content String 聊天內容,當訊息為圖片類型時,content為json字串,下面說明
event String 事件,具體參考聊天室SDK
image String 圖片訊息的圖片位址
msgType String 訊息類型
redpaper:紅包訊息
chatImg:圖片訊息
custom:自訂訊息(透過socket傳送的自訂訊息)
reward:打賞訊息
customerMessage:自訂訊息(透過http介面傳送的自訂訊息)
為空:一般聊天訊息
quote String 引用
sessionId String 場次號
roomId String 房間號
channelId String 頻道號
time Long 傳送訊息時的時間戳
userType String 使用者類型
slice:雲課堂學員
teacher:講師
guest:嘉賓
manager:管理員
assistant:助教
viewer:特邀觀眾
monitor:場監
attendee:研討會參與者
student:一般直播觀眾
status String 審核狀態
pass:已審核
censor:審核中
delete:刪除
sourceType String 訊息來源
public:群聊
extend:管理員私聊
user Object 聊天資訊陣列 【詳見user欄位說明

content為json格式時說明

根據msgType區分訊息類型
msgTyperedpaper時,表示紅包:
參數名 類型 說明
content String 紅包名稱
msgSource String 訊息類型
number Number 紅包數量
redCacheId String 快取的紅包id
redpackId String 紅包id
totalAmount String 紅包總金額
type String 紅包類型,normal為一般紅包,rain為紅包雨,password口令紅包,official_normal開播端-一般紅包
msgTypereward時,表示打賞:
參數名 類型 說明
userId String 使用者ID
goodNum Number 打賞禮物數量
unick String 使用者暱稱
gimg String 禮物圖片位址
rewardContent String 打賞內容
uimg String 使用者頭像
rewardUser Object 打賞者 【詳見rewardUser欄位說明
msgTypechatImg時,表示圖片:
參數名 類型 說明
id String 圖片id
msgSource String 訊息類型
status String 圖片上傳狀態,upLoadingSuccess表示上傳成功
uploadImgUrl String 圖片上傳成功後的位址,多個位址用逗號隔開
size Object 圖片尺寸,width表示圖片寬度,height表示圖片高度
msgTypecustom時,表示自訂訊息:
參數名 類型 說明
msgSource String 訊息類型
EVENT String 自訂訊息事件類型
version String 自訂訊息版本
emitMode Number 自訂訊息廣播方式
tip Number 自訂訊息提示
data Object 自訂訊息體

user欄位說明

參數名 類型 說明
actor String 角色
banned Boolean 是否禁言
channelId String 頻道號
clientIp String 使用者ip
nickname String 觀眾暱稱
pic String 觀眾頭像
roomId String 房間號
sessionId String 場次號
uid String socketId
userId String 使用者唯一標示
userSource String 觀眾來源
userType String 使用者類型
slice:雲課堂學員
teacher:講師
guest:嘉賓
manager:管理員
assistant:助教
viewer:特邀觀眾
monitor:場監
attendee:研討會參與者
student:一般直播觀眾
param4 String 使用者自訂欄位
param5 String 使用者自訂欄位

rewardUser欄位說明

參數名 類型 說明
deviceType String 裝置類型
nick String 觀眾暱稱
uid String socketId
clientIp String 使用者ip
banned Boolean 是否禁言
pic String 使用者頭像
userType String 使用者類型
slice:雲課堂學員
teacher:講師
guest:嘉賓
manager:管理員
assistant:助教
viewer:特邀觀眾
monitor:場監
attendee:研討會參與者
student:一般直播觀眾
customize Number 是否為訂製禮物 0:否 1:是
userId String 使用者id
channelId String 頻道號
roomId String 房間號
scene String 場景
alone:活動直播
ppt:三分屏
topclass:大班課

Java請求範例

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

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

    private static final Logger log = LoggerFactory.getLogger(ChatMessageTest.class);

    /**
     * 查询频道聊天记录
     * @throws IOException
     */
    @Test
    public void testGetMessageList() throws IOException, NoSuchAlgorithmException {
        //公共参数,填写自己的实际参数
        String appId = super.appId;
        String appSecret = super.appSecret;
        String timestamp = String.valueOf(System.currentTimeMillis());
        
        //业务参数
        String url = "http://api.polyv.net/live/v3/channel/chat/get-history-page";
        String startDay = "2020-03-10";
        String endDay = "2021-03-10";
        String channelId = "1965681";
        Integer page = 1;
        Integer pageSize = 20;
        String userType = "";
        String status = "";
        String source = "";
        String roomId = "";
        
        //http 调用逻辑
        Map<String,String> requestMap = new HashMap<>();
        requestMap.put("appId", appId);
        requestMap.put("timestamp",timestamp);
        requestMap.put("startDay",startDay);
        requestMap.put("endDay",endDay);
        requestMap.put("channelId",channelId);
        requestMap.put("page",page.toString());
        requestMap.put("pageSize",pageSize.toString());
        requestMap.put("userType",userType);
        requestMap.put("status",status);
        requestMap.put("source",source);
        requestMap.put("roomId",roomId);
        requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
        String response = HttpUtil.get(url, requestMap);
        log.info("测试查询频道聊天记录接口返回值:{}",response);
    }

回應範例

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

成功範例

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "pageNumber": 1,
        "pageSize": 20,
        "totalPages": 0,
        "totalItems": 0,
        "contents": [
            {
                "id": "874e2850-12bc-11eb-963f-578bb7bc5db5",
                "accountId": "",
                "clientIP": "",
                "content": "hello 大家好",
                "event": null,
                "image": "",
                "msgType": null,
                "quote": null,
                "sessionId": "fs9v9y4nxf",
                "roomId": "1965681",
                "channelId": 1965681,
                "time": 1603188649810,
                "userType": "",
                "status": "",
                "sourceType": "public",
                "user": {
                    "actor": null,
                    "banned": false,
                    "channelId": 1965681,
                    "clientIp": "",
                    "nickname": "thomas",
                    "pic": "http://s1.videocc.net/default-img/avatar/teacher.png",
                    "roomId": "1965681",
                    "sessionId": null,
                    "uid": "",
                    "userId": "1965681_reboot_0",
                    "userSource": null,
                    "userType": ""
                }
            }
        ]
    }
}

異常範例

{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
联系客服,在线咨询