123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Http;
- using LYFZ.Weixin.SDK.Entities;
- using Codeplex.Data;
- namespace LYFZ.Weixin.SDK
- {
-
-
-
-
-
-
-
-
-
-
-
-
- public class AdvanceMassReplayMessageAPI
- {
-
-
-
-
-
-
-
- public static dynamic UploadArtcles(string access_token, List<WeixinArtcle> articles)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token={0}", access_token);
- var client = new HttpClient();
- var result = client.PostAsync(url, new StringContent(DynamicJson.Serialize(articles))).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
-
- public static dynamic UploadVideo(string access_token, string media_id, string title, string description)
- {
- var url = string.Format("https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(media_id).Append(",")
- .Append('"' + "title" + '"' + ":").Append(title)
- .Append('"' + "description" + '"' + ":").Append(description)
- .Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static dynamic Replay(string access_token, string content, WeixinArtcleType type, string group_id, bool is_to_all = false)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "filter" + '"' + ":")
- .Append("{")
- .Append('"' + "is_to_all" + '"' + ":").Append(is_to_all).Append(",")
- .Append('"' + "group_id" + '"' + ":").Append(group_id)
- .Append("},");
- switch (type)
- {
- case WeixinArtcleType.News:
- builder.Append('"' + "mpnews" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("mpnews");
- break;
- case WeixinArtcleType.Text:
- builder.Append('"' + "text" + '"' + ":")
- .Append("{")
- .Append('"' + "content" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("text");
- break;
- case WeixinArtcleType.Voice:
- builder.Append('"' + "voice" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("voice");
- break;
- case WeixinArtcleType.Image:
- builder.Append('"' + "image" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("image");
- break;
- case WeixinArtcleType.Video:
- builder.Append('"' + "mpvideo" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("mpvideo");
- break;
- }
- builder.Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
- public static dynamic ReplayOpenids(string access_token, string content, WeixinArtcleType type, IEnumerable<string> touser, string videoTitle, string videoDesc)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "touser" + '"' + ":")
- .Append("[");
- foreach (var t in touser)
- {
- builder.Append('"' + t + '"').Append(",");
- }
- builder.Append("],");
- switch (type)
- {
- case WeixinArtcleType.News:
- builder.Append('"' + "mpnews" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("mpnews");
- break;
- case WeixinArtcleType.Text:
- builder.Append('"' + "text" + '"' + ":")
- .Append("{")
- .Append('"' + "content" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("text");
- break;
- case WeixinArtcleType.Voice:
- builder.Append('"' + "voice" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("voice");
- break;
- case WeixinArtcleType.Image:
- builder.Append('"' + "image" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("image");
- break;
- case WeixinArtcleType.Video:
- builder.Append('"' + "video" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content).Append(",")
- .Append('"' + "title" + '"' + ":").Append(videoTitle).Append(",")
- .Append('"' + "description" + '"' + ":").Append(videoDesc)
- .Append("},")
- .Append('"' + "msgtype" + '"' + ":").Append("video");
- break;
- }
- builder.Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
- public static dynamic Delete(string access_token, string msg_id)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "msg_id" + '"' + ":").Append(msg_id)
- .Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString()));
- if (!result.Result.IsSuccessStatusCode) return string.Empty;
- return DynamicJson.Parse(result.Result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
-
-
- public static dynamic Preview(string access_token, string openid, string content,WeixinArtcleType type)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "touser" + '"' + ":")
- .Append(openid).Append(",");
- switch (type)
- {
- case WeixinArtcleType.News:
- builder.Append('"' + "mpnews" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"').Append("mpnews");
- break;
- case WeixinArtcleType.Text:
- builder.Append('"' + "text" + '"' + ":")
- .Append("{")
- .Append('"' + "content" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"').Append("text");
- break;
- case WeixinArtcleType.Voice:
- builder.Append('"' + "voice" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"').Append("voice");
- break;
- case WeixinArtcleType.Image:
- builder.Append('"' + "image" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"').Append("image");
- break;
- case WeixinArtcleType.Video:
- builder.Append('"' + "video" + '"' + ":")
- .Append("{")
- .Append('"' + "media_id" + '"' + ":").Append(content)
- .Append("},")
- .Append('"' + "msgtype" + '"').Append("video");
- break;
- }
- builder.Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static dynamic QueryStatus(string access_token, string msg_id)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/mass/get?access_token={0}", access_token);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder.Append("{")
- .Append('"' + "msg_id" + '"' + ":").Append(msg_id)
- .Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString()));
- if (!result.Result.IsSuccessStatusCode) return string.Empty;
- return DynamicJson.Parse(result.Result.Content.ReadAsStringAsync().Result);
- }
- }
- }
|