public UploadResult upload(MediaType type, string fileName) { var url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", weixin.token(), type); var webClient = new WebClient(); var bytes = webClient.UploadFile(url, fileName); var json = System.Text.Encoding.UTF8.GetString(bytes); return(weixin.Deserialize(json, new UploadResult())); }
/// <summary> /// 根据分组进行群发【订阅号与服务号认证后均可用】 /// </summary> public string sendall(string mediaIdOrContent, MessageType msgtype, string group_id) { object filter; if (!string.IsNullOrEmpty(group_id)) { filter = new { is_to_all = false, group_id }; } else { filter = new { is_to_all = true }; } object obj; switch (msgtype) { case MessageType.mpnews: obj = new { filter, mpnews = new { media_id = mediaIdOrContent }, msgtype }; break; case MessageType.text: obj = new { filter, text = new { content = mediaIdOrContent }, msgtype }; break; case MessageType.voice: obj = new { filter, voice = new { media_id = mediaIdOrContent }, msgtype }; break; case MessageType.image: obj = new { filter, image = new { media_id = mediaIdOrContent }, msgtype }; break; default: var msg = string.Format("'{0}' is a unknown media type", msgtype); throw Error.ArugmentNull(msg); } var serial = new System.Web.Script.Serialization.JavaScriptSerializer(); var data = serial.Serialize(obj); var url = "message/mass/sendall?access_token=" + weixin.token(); var json = weixin.GetJson(url, data); var dic = weixin.Deserialize(json, new { msg_id = "" }); return(dic.msg_id); }