123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net.Http;
- using Codeplex.Data;
- using Newtonsoft.Json.Linq;
- namespace LYFZ.Weixin.SDK
- {
-
-
-
-
-
-
-
-
-
-
-
- public class TemplateMessageAPI
- {
-
-
-
-
-
-
-
-
-
- public static dynamic SetIndustry(string access_token, string industry_id1, string industry_id2)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token={0}", access_token);
- CustomMenuAPI.SetServicePointManagerSecurityProtocol(url);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder
- .Append("{")
- .Append('"' + "industry_id1" + '"' + ":").Append(industry_id1).Append(",")
- .Append('"' + "industry_id2" + '"' + ":").Append(industry_id2)
- .Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
- public static dynamic GetTemplates(string access_token, string template_id_short)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={0}", access_token);
- CustomMenuAPI.SetServicePointManagerSecurityProtocol(url);
- var client = new HttpClient();
- var builder = new StringBuilder();
- builder
- .Append("{")
- .Append('"' + "template_id_short" + '"' + ":").Append(template_id_short)
- .Append("}");
- var result = client.PostAsync(url, new StringContent(builder.ToString())).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
- public static Template[] GetAllPrivateTemplates(string access_token, out ErrorMessage errorMessage)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={0}", access_token);
- CustomMenuAPI.SetServicePointManagerSecurityProtocol(url);
- var client = new HttpClient();
- var result = client.GetAsync(url).Result;
-
- Template[] templates;
- errorMessage = Template.Parse(result.Content.ReadAsStringAsync().Result, out templates);
- return templates;
- }
-
-
-
-
-
-
-
-
-
-
- public static dynamic SendTemplateMessage(string access_token, dynamic content)
- {
-
- string contentStr = content.ToString();
- return SendTemplateMessage(access_token, contentStr);
- }
-
-
-
-
-
-
-
-
-
- public static dynamic SendTemplateMessage(string access_token, string content)
- {
- var url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", access_token);
- CustomMenuAPI.SetServicePointManagerSecurityProtocol(url);
- var client = new HttpClient();
- var result = client.PostAsync(url, new StringContent(content)).Result;
- return DynamicJson.Parse(result.Content.ReadAsStringAsync().Result);
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public static dynamic SendTemplateMessage(string access_token, string touser, string template_id, string url,dynamic data)
- {
- dynamic sendContent = new
- {
- touser = touser,
- template_id = template_id,
- url = url,
- data = data
- };
- return SendTemplateMessage(access_token, sendContent);
- }
- }
- }
|