由于业务原因,需要在群内发送通知消息,写完后不好使,请问是什么原因
public AjaxResult sendText(ImMessage imMessage) {
Conversation conversation = new Conversation();
conversation.setTarget(imMessage.getTarget());//目标群
conversation.setType(ProtoConstants.ConversationType.ConversationType_Group);
MessagePayload payload = new MessagePayload();
payload.setType(1);
payload.setSearchableContent("通知");
//k是被通知的人,v是list 是通知的内容
imMessage.getNotices().forEach((k, v) -> {
v.forEach(item -> {
payload.setPushContent(item);
payload.setPushData("通知");
//0 不提醒;1 对mentionedTargets里的user进行提醒;2 对群内所有人提醒。
payload.setMentionedType(1);//@别人
payload.setMentionedTarget(Collections.singletonList(k));//@ 的人
// 发消息时固定使用admin用户
TUser user = tUserService.selectTUserById(2L);
try {
//发送消息
IMResult<SendMessageResult> resultSendMessage = MessageAdmin.sendMessage(user.getUid(), conversation, payload);
if (resultSendMessage == null || resultSendMessage.getErrorCode() != ErrorCode.ERROR_CODE_SUCCESS) {
throw new ServiceException("发送通知失败");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
});
return AjaxResult.success();
}