/// <summary> /// 发送视频客服信息 /// </summary> /// <param name="accessToken">调用凭据</param> /// <param name="toUser">接收方</param> /// <param name="title">视频标题</param> /// <param name="description">视频描述</param> /// <param name="videoPath">视频文件路径</param> /// <returns></returns> public static SendCustomMessageResponse SendVideoCustomMessage(string accessToken, string toUser, string title, string description, string videoPath) { IMpClient mpClient = new MpClient(); UploadMediaRequest request = new UploadMediaRequest() { AccessToken = accessToken, Type = "video", FileName = videoPath }; UploadMediaResponse response = mpClient.Execute(request); if (response.IsError) { SendCustomMessageResponse response2 = new SendCustomMessageResponse() { Body = response.Body, ErrInfo = response.ErrInfo, ReqUrl = response.ReqUrl }; return(response2); } VideoCustomMessage msg = new VideoCustomMessage() { AccessToken = accessToken, MediaId = response.MediaId, MsgType = "video", ToUser = toUser, Description = description, Title = title }; return(SendCustomMessage(accessToken, msg)); }
/// <summary> /// 发送图片客服消息 /// </summary> /// <param name="accessToken">调用凭据</param> /// <param name="toUser">接收方</param> /// <param name="imgPath">图片路径</param> /// <returns></returns> public static SendCustomMessageResponse SendImageCustomMessage(string accessToken, string toUser, string imgPath) { IMpClient mpClient = new MpClient(); UploadMediaRequest request = new UploadMediaRequest() { AccessToken = accessToken, Type = "image", FileName = imgPath }; UploadMediaResponse response = mpClient.Execute(request); if (response.IsError) { SendCustomMessageResponse response2 = new SendCustomMessageResponse() { Body = response.Body, ErrInfo = response.ErrInfo, ReqUrl = response.ReqUrl }; return(response2); } ImageCustomMessage msg = new ImageCustomMessage() { AccessToken = accessToken, MediaId = response.MediaId, MsgType = "image", ToUser = toUser }; return(SendCustomMessage(accessToken, msg)); }
/// <summary> /// 发送被动响应音乐消息 /// </summary> /// <param name="accessToken">调用接口凭证</param> /// <param name="fromUserName">发送方</param> /// <param name="toUserName">接收方</param> /// <param name="title">标题</param> /// <param name="description">描述</param> /// <param name="musicUrl">音乐链接</param> /// <param name="hqMusicUrl">高质量音乐链接</param> /// <param name="thumbMediaFilePath">缩略图文件路径(64KB,支持JPG格式 )</param> /// <returns>是否成功</returns> public static bool SendMusicReplyMessage(string accessToken, string fromUserName, string toUserName, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath) { IMpClient mpClient = new MpClient(); UploadMediaRequest request = new UploadMediaRequest() { AccessToken = accessToken, Type = "thumb", FileName = thumbMediaFilePath }; UploadMediaResponse response = mpClient.Execute(request); if (response.IsError) { return(false); } else { MusicReplyMessage msg = new MusicReplyMessage() { CreateTime = Tools.ConvertDateTimeInt(DateTime.Now), FromUserName = fromUserName, ToUserName = toUserName, Description = description, Title = title, ThumbMediaId = response.MediaId, HQMusicUrl = hqMusicUrl, MusicURL = musicUrl }; System.Web.HttpContext.Current.Response.Write(msg.ToXmlString()); return(true); } }
/// <summary> /// 发送被动响应语音消息 /// </summary> /// <param name="accessToken">调用接口凭证</param> /// <param name="fromUserName">发送方</param> /// <param name="toUserName">接收方</param> /// <param name="voicePath">语音文件路径(支持AMR\MP3,最大256K,播放长度不超过60s)</param> /// <returns>是否成功</returns> public static bool SendVoiceReplyMessage(string accessToken, string fromUserName, string toUserName, string voicePath) { IMpClient mpClient = new MpClient(); UploadMediaRequest request = new UploadMediaRequest() { AccessToken = accessToken, Type = "voice", FileName = voicePath }; UploadMediaResponse response = mpClient.Execute(request); if (response.IsError) { return(false); } else { VoiceReplyMessage msg = new VoiceReplyMessage() { CreateTime = Tools.ConvertDateTimeInt(DateTime.Now), FromUserName = fromUserName, ToUserName = toUserName, MediaId = response.MediaId }; System.Web.HttpContext.Current.Response.Write(msg.ToXmlString()); return(true); } }
/// <summary> /// 发送客服信息 /// </summary> /// <param name="accessToken">调用凭据</param> /// <param name="msg">客服消息</param> /// <returns></returns> public static SendCustomMessageResponse SendCustomMessage(string accessToken, CustomMessage msg) { IMpClient mpClient = new MpClient(); SendCustomMessageRequest request = new SendCustomMessageRequest() { AccessToken = accessToken, SendData = msg.ToJsonString() }; SendCustomMessageResponse response = mpClient.Execute(request); return(response); }
/// <summary> /// 发送音乐客服信息 /// </summary> /// <param name="accessToken">调用凭据</param> /// <param name="toUser">接收方</param> /// <param name="title">音乐标题</param> /// <param name="description">音乐描述</param> /// <param name="musicUrl">音乐地址</param> /// <param name="hqMusicUrl">高质量音乐地址</param> /// <param name="thumbMediaFilePath">音乐缩略图路径</param> /// <returns></returns> public static SendCustomMessageResponse SendMusicCustomMessage(string accessToken, string toUser, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaFilePath) { IMpClient mpClient = new MpClient(); UploadMediaRequest request = new UploadMediaRequest() { AccessToken = accessToken, Type = "thumb", FileName = thumbMediaFilePath }; UploadMediaResponse response = mpClient.Execute(request); if (response.IsError) { SendCustomMessageResponse response2 = new SendCustomMessageResponse() { Body = response.Body, ErrInfo = response.ErrInfo, ReqUrl = response.ReqUrl }; return(response2); } MusicCustomMessage msg = new MusicCustomMessage() { AccessToken = accessToken, ThumbMediaId = response.MediaId, HqMusicUrl = hqMusicUrl, MusicUrl = musicUrl, MsgType = "music", ToUser = toUser, Description = description, Title = title }; return(SendCustomMessage(accessToken, msg)); }