/// <summary> /// 上传多媒体文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { string userName = lbPublicAccount.SelectedValue; MultiMediaTypeEnum type = (MultiMediaTypeEnum)Enum.Parse(typeof(MultiMediaTypeEnum), lbMultiMediaType.SelectedValue); string filename = fileUpload.FileName; byte[] bytes = fileUpload.FileBytes; ErrorMessage errorMessage; MultiMediaUploadResult result = MultiMediaHelper.Upload(userName, type, filename, bytes, out errorMessage); if (errorMessage.IsSuccess && result != null) { hlShowMultiMedia.NavigateUrl = MultiMediaHelper.GetDownloadUrl(AccessToken.Get(userName).access_token, result.MediaId); ltrMessage.Text = "上传多媒体文件成功。"; } else { hlShowMultiMedia.NavigateUrl = string.Format("javascript:alert('上传多媒体文件失败。\r\n{0}');", errorMessage); ltrMessage.Text = string.Format("上传多媒体文件失败。\r\n{0}", errorMessage); } }
/// <summary> /// 新增临时素材(多媒体文件) /// </summary> /// <param name="userName">公众号</param> /// <param name="type">媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)</param> /// <param name="fileName">文件名(不包含路径)</param> /// <param name="data">数据</param> /// <param name="errorMessage">返回上传是否成功</param> /// <returns>返回上传多媒体文件的结果;如果上传失败,返回null。</returns> public static MultiMediaUploadResult AddTemporary(string userName, MultiMediaTypeEnum type, string fileName, byte[] data, out ErrorMessage errorMessage) { return(MultiMediaHelper.Upload(userName, type, fileName, data, out errorMessage)); }
/// <summary> /// 新增临时素材(图文消息) /// </summary> /// <param name="userName">公众号</param> /// <param name="articles">图文消息</param> /// <param name="errorMessage">返回上传是否成功</param> /// <returns>返回上传图文消息的结果;如果上传失败,返回null。</returns> public static MultiMediaUploadResult AddTemporary(string userName, IEnumerable <MultiMediaArticle> articles, out ErrorMessage errorMessage) { return(MultiMediaHelper.Upload(userName, articles, out errorMessage)); }
/// <summary> /// 新增临时素材(多媒体文件) /// </summary> /// <param name="userName">公众号</param> /// <param name="type">媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)</param> /// <param name="pathName">包含路径的文件名</param> /// <param name="errorMessage">返回上传是否成功</param> /// <returns>返回多媒体上传结果;如果上传失败,返回null。</returns> public static MultiMediaUploadResult AddTemporary(string userName, MultiMediaTypeEnum type, string pathName, out ErrorMessage errorMessage) { return(MultiMediaHelper.Upload(userName, type, pathName, out errorMessage)); }