Copy 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);
}