Polyv Help Center

Help Center

(Hideable) Send Image and Text Message

Updated: 2022-09-02 18:08:07

API Description

1、通过聊天室API,发送图文信息
2、接口支持https协议
3、接口URL中的{channelId}为"频道号"

API URL

http://api.polyv.net/live/v1/channelSetting/{channelId}/send-chat

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details

Request Parameters

Parameter Required Type Description
appId true String Account appId See details on obtaining keys
timestamp true Long Current 13-digit millisecond timestamp, valid within 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 side. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules
userId true String Live streaming account ID
content/imgUrl true String The image or text to send. Both cannot be empty simultaneously, but can be submitted together. Content must be base64 encoded. See URL-safe base64 encoding rules

URL-safe Base64 Encoding Rules

Java

public static String encodeBase64URLSafeString(String text) {
        byte[] data = org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(text.getBytes(StandardCharsets.UTF_8));
        return new String(data, StandardCharsets.UTF_8);
}

PHP

function urlsafe_b64encode($string) {
        $data = base64_encode($string);
        $data = str_replace(array('+','/','='), array('-','_',''), $data);
        return $data;
}

Example

http://api.polyv.net/live/v1/channelSetting/2191569/send-chat

Form Parameters:

appId=frlr1zazn3&sign=47B9259E6E93CA2E15B33D532E813417&userId=1b448be323&content=5rWL6K-V77yI5Y-v6ZqQ6JeP77yJ5Y-R6YCB5Zu-5paH5L-h5oGv&timestamp=1616641094219

Response Parameters

Parameter Type Description
status String Response status text
result String Response data

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download source code. After downloading, add it to your own source project. The test case files HttpUtil.java and LiveSignUtil.java are included in the download package.

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 pooling.

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

// URL安全的字符串base64编码
public static String encodeBase64URLSafeString(String text) {
        byte[] data = org.apache.commons.codec.binary.Base64.encodeBase64URLSafe(text.getBytes(StandardCharsets.UTF_8));
        return new String(data, StandardCharsets.UTF_8);
}

/**
 * (可隐藏)发送图文信息
 * @throws IOException
 */
@Test
public void testSendHiddenMessage() throws IOException, NoSuchAlgorithmException {
        //公共参数,填写自己的实际参数
        String appId = super.appId;
        String appSecret = super.appSecret;
        String userId = super.userId;
        String timestamp = String.valueOf(System.currentTimeMillis());

        //业务参数
        String channelId = "2191569";
        String url = "http://api.polyv.net/live/v1/channelSetting/"+channelId+"/send-chat";
        String content = encodeBase64URLSafeString("测试(可隐藏)发送图文信息");

        //http 调用逻辑
        Map<String,String> requestMap = new HashMap<>();
        requestMap.put("appId", appId);
        requestMap.put("timestamp",timestamp);
        requestMap.put("content",content);
        requestMap.put("userId",userId);
        requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
        String response = HttpUtil.postFormBody(url, requestMap);
        log.info("测试(可隐藏)发送图文信息接口返回值:{}",response);

}

Response Example

For global system error descriptions, see Global Error Descriptions

Success Example

{
  "status": "success",
  "result": ""
}

Error Example

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