/// <summary> /// 上传图文消息 /// </summary> /// <param name="userName">公众号</param> /// <param name="articles">图文消息</param> /// <param name="errorMessage">返回上传是否成功</param> /// <returns>返回上传图文消息的结果;如果上传失败,返回null。</returns> public static MultiMediaUploadResult Upload(string userName, IEnumerable <MultiMediaArticle> articles, out ErrorMessage errorMessage) { if (articles == null) { errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "图文消息不能为空。"); return(null); } AccessToken token = AccessToken.Get(userName); if (token == null) { errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "获取许可令牌失败。"); return(null); } string url = string.Format(urlForUploadingArticles, token.access_token); string responseContent; HttpHelper.Request(url, out responseContent, WebRequestMethods.Http.Post, MultiMediaArticle.ToJson(articles)); return(ParseResult(responseContent, out errorMessage)); }
/// <summary> /// 新增永久图文素材 /// </summary> /// <param name="userName">公众号</param> /// <param name="articles">图文消息</param> /// <param name="errorMessage">返回新增是否成功</param> /// <returns>返回图文消息的媒体id;如果失败,返回null。</returns> public static string Add(string userName, IEnumerable <MultiMediaArticle> articles, out ErrorMessage errorMessage) { string responseContent = HttpHelper.RequestResponseContent(urlForAddingNews, userName, null, httpMethodForEditing, MultiMediaArticle.ToJson(articles)); return(GetMediaId(responseContent, out errorMessage)); }