有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

功能描述

支持发送文本、自定义、富媒体消息,消息类型都是 Message

重点接口说明

接口 MsgSendMessage点击查看详情)是发送消息中最核心的接口。该接口支持发送所有类型的消息。
接口说明如下:
Type
Name
Description
System.String
conv_id
会话ID
TIMConvType
conv_type
会话类型 TIMConvType
Message
message
消息体 Message
System.Text.StringBuilder
message_id
承接消息 ID 的 StringBuilder
ValueCallback | ValueCallback
callback
异步回调

发送文本消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Text,
text_elem_content = "这是一个普通文本消息"
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送图片消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Image,
image_elem_orig_path = "/Users/xxx/xxx.png", // 文件绝对路径
image_elem_level = TIMImageLevel.kTIMImageLevel_Orig // 原图发送
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送语音消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Sound,
sound_elem_file_path = "/Users/xxx/xxx.mp3", // 文件绝对路径
sound_elem_file_size = 10 // 语音时长

}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送视频消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Video,
video_elem_video_path = "/Users/xxx/xxx.mp4", // 文件绝对路径
video_elem_video_type = "mp4", // 视频类型
video_elem_video_duration = 10, // 视频时长

video_elem_image_path = "本地视频封面文件绝对路径",
video_elem_image_type = "png", // 视频截图文件类型
video_elem_image_size = 100, // 视频截图文件大小
video_elem_image_width = 1920, // 视频截图文件宽
video_elem_image_height = 1080, // 视频截图文件高
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送文件消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_File,
file_elem_file_path = "/Users/xxx/xxx.x", // 文件绝对路径
file_elem_file_name = "文件名",
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送定位消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Location,
location_elem_desc = "深圳市南山区深南大道", // 位置信息摘要
location_elem_longitude = 34, // 经度
location_elem_latitude = 20 // 纬度
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送表情消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Face,
face_elem_index = 0,
face_elem_buf = ""
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

发送自定义消息

public static void MsgSendMessage() {
string conv_id = ""; // c2c 消息会话 ID 为 userID,群消息会话 ID 为 groupID
Message message = new Message
{
message_conv_id = conv_id,
message_conv_type = TIMConvType.kTIMConv_C2C, // 群消息为TIMConvType.kTIMConv_Group
message_elem_array = new List<Elem>
{
new Elem
{
elem_type = TIMElemType.kTIMElem_Custom,
custom_elem_data = "",
custom_elem_desc = "",
custom_elem_ext = ""
}
}
};
StringBuilder messageId = new StringBuilder(128);

TIMResult res = TencentIMSDK.MsgSendMessage(conv_id, TIMConvType.kTIMConv_C2C, message, messageId, (int code, string desc, string json_param, string user_data)=>{
// 消息发送异步结果
});
// 消息发送同步返回的消息ID messageId
}

交流与反馈

点此进入IM社群,享有专业工程师的支持,解决您的难题