Polyv Help Center

Help Center

Send Approved Chat Message

Updated: 2023-04-04 09:31:23

API Description

1、发送审核通过的聊天消息
2、(channelId, timestamp, appId)参与sign签名,并和sign一起通过url传递,请求体参数不参与签名,通过post请求体传递【请设置请求头contentType:application/json】
3、接口支持https协议

API URL

http://api.polyv.net/live/v4/chat/message/audit

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure API security. API calls are subject to rate limits. Click for details

Request Parameter Description

Parameter Required Type Description
appId true String Account appId See: Get Secret Key
channelId true String Channel ID
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See: Signature Generation Rules
timestamp true String Current 13-digit millisecond timestamp, valid for 3 minutes

Request Body Parameter Description

Parameter Required Type Description
msgId true String Custom msgId, no more than 32 characters
viewerId true String Viewer ID, no more than 64 characters
nickName true String Viewer nickname, no more than 128 characters
content true String Message content, no more than 2000 characters
avatar false String Viewer avatar URL, no more than 200 characters; if not provided, the user avatar corresponding to viewerId will be used when online, otherwise the default avatar is used
sessionId false String Session ID
viewerType false String Viewer type, viewer: viewer, student: student, slice: cloud classroom student

Example

http://api.polyv.net/live/v4/chat/message/audit?appId=fxlwyesvqd&sign=942AC99EACD1D11FF35E480414403EB0&timestamp=1680162971000&channelId=3808479

Request body JSON parameters:

[
    {
        "msgId":"msg-1",
        "content":"我发送了一条消息",
        "viewerId":"sadboy",
        "nickName":"polyv"
    }
]

Response Parameter Description

Parameter Type Description
code Integer Status code, same as HTTP status code, used to determine the basic response status
data Array Data for successful response See: Data Parameter Description
error Object Error information when status code is not 200 See: Error Parameter Description
requestId String Request ID, a unique UUID generated for each request, only for troubleshooting and debugging, should not be tied to business logic
status String Response result, determined by business logic, returns success on success, error on failure
success Boolean Whether the response was successful

Data Parameter Description

Parameter Type Description
id String Polyv chat room message ID
msg String Error or success message, e.g., Sent successfully
msgId String External message ID, i.e., the msgId from the request parameters
status Boolean Whether the message was sent successfully, true: success, false: failure

Error Parameter Description

Parameter Type Description
code Integer Error code, used to identify the specific error cause
desc String Error description, corresponding to error.code

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source code project. The test cases include HttpUtil.java and LiveSignUtil.java in the downloaded file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(getClass());
/**
 * 审核通过聊天信息
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void messageAuditTest() 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/chat/message/audit";
    String channelId = "1965681";
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("channelId", channelId);
    requestMap.put("timestamp", timestamp);
    
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    
    url = HttpUtil.appendUrl(url, requestMap);
    
    Map<String, String> jsonMap = new HashMap<>();
    jsonMap.put("msgId","msg-1");
    jsonMap.put("content","我发送了一条消息");
    jsonMap.put("viewerId","sadboy");
    jsonMap.put("nickName","polyv");
    List<Map<String, String>> list = new ArrayList<>();
    list.add(jsonMap);
    
    String response = HttpUtil.postJsonBody(url,JSON.toJSONString(list),null);
    
    log.info("测试审核通过聊天信息成功:{}", response);
    //do somethings
    
}

Response Example

For global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "requestId": "807edf69deb540cd8b1f7a8b0e2dc883.64.16801629319610385",
    "data": [
        {
            "msgId": "123",
            "id": "3ec969a0-ced0-11ed-87bd-6de896f75816",
            "status": true,
            "msg": "发送成功"
        }
    ],
    "success": true
}

Error Example

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