/// <summary> /// 上传图片素材 /// 上传在摇一摇页面展示的图片素材,素材保存在微信侧服务器上。 格式限定为:jpg,jpeg,png,gif,图片大小建议120px*120 px,限制不超过200 px *200 px,图片需为正方形。 /// </summary> /// <param name="accessToken"></param> /// <param name="file"></param> /// <param name="timeOut"></param> /// <returns></returns> public static UploadImageResultJson UploadImage(string accessToken, string file, int timeOut = Config.TIME_OUT) { var url = string.Format("https://api.weixin.qq.com/shakearound/material/add?access_token={0}", accessToken); var fileDictionary = new Dictionary <string, string>(); fileDictionary["media"] = file; return(PostMethod.PostFileGetJson <UploadImageResultJson>(url, null, fileDictionary, null, timeOut: timeOut)); }
/// <summary> /// 新增临时素材(原上传媒体文件) /// </summary> /// <param name="accessToken"></param> /// <param name="type"></param> /// <param name="file"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static UploadTemporaryMediaResult UploadTemporaryMedia(string accessToken, UploadMediaFileType type, string file, int timeOut = Config.TIME_OUT) { var url = string.Format("http://api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", accessToken, type.ToString()); var fileDictionary = new Dictionary <string, string>(); fileDictionary["media"] = file; return(PostMethod.PostFileGetJson <UploadTemporaryMediaResult>(url, null, fileDictionary, null, timeOut: timeOut)); }
/// <summary> /// 上传客服头像 /// </summary> /// <param name="accessToken"></param> /// <param name="kfAccount">完整客服账号,格式为:账号前缀@公众号微信号</param> /// <param name="file">form-data中媒体文件标识,有filename、filelength、content-type等信息</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static WxJsonResult UploadCustomHeadimg(string accessToken, string kfAccount, string file, int timeOut = Config.TIME_OUT) { var url = string.Format("http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token={0}&kf_account={1}", accessToken, kfAccount); var fileDictionary = new Dictionary <string, string>(); fileDictionary["media"] = file; return(PostMethod.PostFileGetJson <WxJsonResult>(url, null, fileDictionary, null, timeOut: timeOut)); }
/// <summary> /// 新增永久视频素材 /// </summary> /// <param name="accessToken"></param> /// <param name="file">文件路径</param> /// <param name="title"></param> /// <param name="introduction"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static UploadForeverMediaResult UploadForeverVideo(string accessToken, string file, string title, string introduction, int timeOut = Config.TIME_OUT) { var url = string.Format("http://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}", accessToken); var fileDictionary = new Dictionary <string, string>(); fileDictionary["media"] = file; fileDictionary["description"] = string.Format("{{\"title\":\"{0}\", \"introduction\":\"{1}\"}}", title, introduction); return(PostMethod.PostFileGetJson <UploadForeverMediaResult>(url, null, fileDictionary, null, timeOut: timeOut)); }
/// <summary> /// 新增其他类型永久素材(图片(image)、语音(voice)和缩略图(thumb)) /// </summary> /// <param name="accessToken"></param> /// <param name="file">文件路径</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static UploadForeverMediaResult UploadForeverMedia(string accessToken, string file, int timeOut = Config.TIME_OUT) { var url = string.Format("http://api.weixin.qq.com/cgi-bin/material/add_material?access_token={0}", accessToken); //因为有文件上传,所以忽略dataDictionary,全部改用文件上传格式 //var dataDictionary = new Dictionary<string, string>(); //dataDictionary["type"] = UploadMediaFileType.image.ToString(); var fileDictionary = new Dictionary <string, string>(); //fileDictionary["type"] = UploadMediaFileType.image.ToString();//不提供此参数也可以上传成功 fileDictionary["media"] = file; return(PostMethod.PostFileGetJson <UploadForeverMediaResult>(url, null, fileDictionary, null, timeOut: timeOut)); }