1、通过聊天室API,发送图文信息
2、接口支持https协议
3、接口URL中的{channelId}为"频道号"
http://api.polyv.net/live/v1/channelSetting/{channelId}/send-chat
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);
}
function urlsafe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='), array('-','_',''), $data);
return $data;
}
http://api.polyv.net/live/v1/channelSetting/2191569/send-chat
appId=frlr1zazn3&sign=47B9259E6E93CA2E15B33D532E813417&userId=1b448be323&content=5rWL6K-V77yI5Y-v6ZqQ6JeP77yJ5Y-R6YCB5Zu-5paH5L-h5oGv×tamp=1616641094219
强烈建议您使用直播Java SDK完成API的功能对接,直播Java SDK 对API调用逻辑、异常处理、数据签名、HTTP请求线程池进行了统一封装和优化。
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);
}
{
"status": "success",
"result": ""
}
{
"code": 400,
"status": "error",
"message": "invalid signature.",
"data": ""
}