保利威文档中心

幫助中心

建立互動監聽事件

更新時間:2026-05-22 10:21:24

介面描述

1、创建互动监听事件
2、接口支持https协议

介面URL

https://api.polyv.net/live/v4/channel/interaction-event/save

請求方式

POST

介面限制

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

請求參數描述

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

請求體參數描述

參數名 必填 類型 說明
channelId true Integer 頻道ID
tasks true Array 任務規則列表 【詳見tasks欄位說明
callbackUrl false String 回呼URL
allDone true String 是否tasks中的任務全部完成才算完成任務:Y 或 N
payload false String 有效負載

回呼說明(POST請求)

參數名 類型 說明
roomId String 房間ID
accountId String 帳號ID
content String 使用者完成任務列表,json陣列,詳見content參數說明
requestId String 請求ID
timestamp Long 目前13位毫秒級時間戳
sign String 簽名驗證,產生規則為:polyvlog + 数据key和value组成 + polyvlog,其中数据key按首字母從小到大排序。 md5轉碼後,轉為大寫。例如,參數為{roomId:'200060', channelId:'005200060',user:{nick:'yang'}},則簽名為\nmd5/('polyvChatSign'+'channelId'+'005200060'+'roomId'+'200060'+'user'+JSON.stringify({nick:'yang'})+'polyvChatSign').toLocaleUpperCase();'}
totalBatch Integer 目前任務總批次數
currentBatch Integer 任務目前批次數
content 陣列物件說明
參數名 類型 說明
data Array 任務完成詳情列表,詳見data列表說明
taskId String 任務ID
activityId String 活動ID
taskData Object 任務自訂資料
data 列表說明
參數名 類型 說明
userId String 使用者ID
回呼回應說明

回呼介面的回應體需要滿足以下任一條件,否則系統會進行重試,連續5次失敗後放棄回呼:

  • code 欄位的值為 200
  • status 欄位的值為 success

tasks參數描述

參數名 必填 類型 說明
startTime true Long 開始時間
endTime true Long 結束時間
type true String 任務條件(線上、簽到)type為onlineTime時有onlineTime;type為signCount時有signCount;type為speakCount時有speakCount和speakContent,表示達到speakCount次,且評論內容為speakContent;type為customCount時有customCount;type為customCount時有eventType;type可以取值loginList;type為taskEndTimeOnline表示任務完成時,且使用者線上,則觸發任務
onlineTime false Integer 線上時長(單位為毫秒)
signCount false Integer 簽到次數
userTags false Array 使用者標籤
speakCount false Integer 評論次數
speakContent false String 評論內容
customCount false Integer 自訂計數
eventType false String 事件類型
payload false String 有效負載,500字元以內

範例

https://api.polyv.net/live/v4/channel/interaction-event/save?appId=frlr1zazn3&sign=012332FBD8DBCFC068AFCB484A2ADECB&timestamp=1670550787318

請求體json參數:

{
    "channelId": 5392252,
    "tasks": [
        {
          "type":"signCount",
          "signCount": 2,
          "startTime": 1733888246000,
          "endTime":   1733888426000
        }
    ],
    "callbackUrl" : "http://callback/write",
    "allDone": "Y"
}

回應體json:

{
  "code": 200,
  "status": "success",
  "requestId": "5b7d9087-c632-4607-93de-ed3da2c7a4cf",
  "data": {
    "activityId": "95564091-b835-11ef-9283-17521e995374",
    "list": [
      {
        "taskId": "95564090-b835-11ef-9283-17521e995374",
        "result": {
          "status": "success",
          "message": "",
          "code": 200,
          "data": ""
        }
      }
    ]
  },
  "message": "添加任务成功",
  "success": true
}

回應參數描述

參數名 類型 說明
code Integer 回應狀態碼,200為成功返回,非200為失敗
status String 回應結果,由業務決定,成功返回success,失敗返回error
success Boolean 回應結果,由業務決定,成功返回true,失敗返回false
data Object 裡面返回taskId
error Object 狀態碼非200時的錯誤資訊【詳見Error欄位說明
requestId String 請求ID,每次請求產生的唯一的 UUID,僅可用於排查、除錯,不應該和業務掛上鉤

Error參數描述

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

Java請求範例

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

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

private final Logger log = LoggerFactory.getLogger(getClass());
/**
 * 新建监听事件
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void createTest() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
        
    String url = "https://api.polyv.net/live/v4/channel/interaction-event/save";
    //业务参数
    Integer channelId = 5004544;
    String activityName = "demoData";
    Integer taskRule = 1;
    Long startTime = 1722035312584;
    Long endTime = 1722036312584;
    List<Task> tasks = new ArrayList();
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
        
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("channelId", channelId);
    jsonMap.put("tasks", tasks);
    jsonMap.put("callbackUrl", "http://callback/write");
    jsonMap.put("allDone", "Y");
    
    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": "5b7d9087-c632-4607-93de-ed3da2c7a4cf",
  "data": {
    "activityId": "95564091-b835-11ef-9283-17521e995374",
    "list": [
      {
        "taskId": "95564090-b835-11ef-9283-17521e995374",
        "result": {
          "status": "success",
          "message": "",
          "code": 200,
          "data": ""
        }
      }
    ]
  },
  "message": "添加任务成功",
  "success": true
}

異常範例

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
{
    "code": 200,
    "status": "success",
    "requestId": "29fc71ae-110f-43f2-87f0-4d60a6c743ff",
    "data": {
        "list": [
            {
                "taskId": "2368e870-b835-11ef-9283-17521e995374",
                "result": {
                    "status": "error",
                    "message": "time is too long",
                    "code": 505,
                    "data": {}
                }
            }
        ],
        "activityId": "2368e871-b835-11ef-9283-17521e995374"
    },
    "message": "添加任务成功",
    "success": true
}
联系客服,在线咨询