/// <summary> /// 图片不占用公众号的素材库中图片数量的100000个的限制, /// 图片仅支持jpg/png格式,大小必须在1MB以下。 /// </summary> /// <param name="access_token">公众号access token</param> /// <param name="filepath">素材物理路径</param> /// <param name="timeout">超时时间,单位毫秒</param> /// <returns></returns> public MaterialResult UploadImg(string access_token, string filepath, int timeout = 1200000) { string url = $"{Config.WxApi}cgi-bin/media/uploadimg?access_token={access_token}"; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("media", filepath); MaterialResult result = this.AddFileToWeChat <MaterialResult>(url, dic, timeout); return(result); }
/// <summary> /// 新增其他类型永久素材 /// </summary> /// <param name="access_token"></param> /// <param name="type"> 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)</param> /// <param name="filepath">素材物理路径</param> /// <param name="title">视频标题,上传视频素材时此字段才有意义</param> /// <param name="introduction">视频简介,上传视频素材时此字段才有意义</param> /// <param name="timeout">超时时间,单位毫秒</param> /// <returns></returns> public MaterialResult AddMaterial(string access_token, string type, string filepath, string title, string introduction = "INTRODUCTION", int timeout = 1200000) { string url = $"{Config.WxApi}cgi-bin/material/add_material?access_token={access_token}&type={type}"; var fileDictionary = new Dictionary <string, string> { ["media"] = filepath, ["description"] = "{\"title\":\"" + title + "\", \"introduction\":\"" + introduction + "\"}" }; MaterialResult result = this.AddFileToWeChat <MaterialResult>(url, fileDictionary, timeout); return(result); }