Send Custom Message
API Description
1、发送聊天室自定义消息
2、接口支持https协议
API URL
http://api.polyv.net/live/v4/chat/send-custom-message/encode
Request Method
POST
API Constraints
The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
The text content (content) or image URL (imgUrl) to be sent cannot both be empty. They can be submitted simultaneously.
The text content (content) to be sent must be URL-safe base64 encoded.
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | true | String | Account appId See details on obtaining keys |
| timestamp | true | Long | Current 13-digit millisecond timestamp, valid for 3 minutes |
| 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 stored or used directly on the client. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules |
| channelId | true | String | Channel ID |
| content | false | String | Text content to send. Must be URL-safe base64 encoded. Maximum length after encoding is 1500 characters. |
| imgUrl | false | String | Image URL to send |
| joinHistoryList | false | Integer | Whether to include in chat history. Default is 1. 1: Include in chat history 0: Do not include |
| watchType | false | Integer | Target audience for this message (default is 1) 1: All roles in the channel 2: Only viewers in the channel 3: Only special roles (lecturer, guest, assistant, admin) |
Example
http://api.polyv.net/live/v4/chat/send-custom-message/encode?joinHistoryList=0&appId=frlr1zazn3&sign=94CAD8CB13062C904F193ED3958CE7DB&channelId=2272655×tamp=1676561050174
Form Parameters:
content=5ZCM5a2m5Lus77yM5pma5LiK5aW977yB6L-Z5piv5oiR5Lus55qE56ys5LiA5aCC6K--77yB
Response Parameter Description
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Status code, same as HTTP status code, used to determine basic response status |
| status | String | Response result, determined by business logic. Returns "success" on success, "error" on failure |
| success | Boolean | Whether the response was successful |
| requestId | String | Request ID, a unique UUID generated for each request. Only used for troubleshooting and debugging, not related to business logic |
| error | Object | Error information when status code is not 200 See Error field description |
| data | Object | Returns null on successful response |
Error Parameter Description
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Error code, used to determine the specific error reason |
| 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 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 packaging and optimization for API call logic, exception handling, data signing, and HTTP request thread pooling.
private static final Logger log = LoggerFactory.getLogger(getClass());
/**
* 发送聊天室自定义消息
* @throws IOException
* @throws NoSuchAlgorithmException
*/
@Test
public void sendCustomMessageEncodeTest() 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/send-custom-message/encode";
String channelId = "2272655";
String content = "同学们,晚上好!这是我们的第一堂课!";
String joinHistoryList = "0";
content = new String(
org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(content.getBytes(StandardCharsets.UTF_8)));
//http 调用逻辑
Map<String, String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp", timestamp);
requestMap.put("channelId", channelId);
requestMap.put("joinHistoryList", joinHistoryList);
requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
url = HttpUtil.appendUrl(url, requestMap);
Map<String, String> paramMap = new HashMap<>();
paramMap.put("content", content);
String response = HttpUtil.postFormBody(url, paramMap);
log.info("测试发送聊天室自定义消息成功:{}", response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"requestId": "8cdf6088d1dc42abbe8727f402d502ac.73.16765610518450895",
"data": null,
"success": true
}
Error Example
{
"code": 400,
"status": "error",
"requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
"error": {
"code": 20001,
"desc": "application not found."
},
"success": false
}
