码迷,mamicode.com
首页 > 微信 > 详细

微信推送模板消息

时间:2015-08-01 06:21:42      阅读:707      评论:0      收藏:0      [点我收藏+]

标签:

在微信的服务号中,往往需要对订阅用户推送消息,有时候会用到模板消息,下面的代码仅供参考,个人测试成功。

@access_token 请调用 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=@appid&secret=@secret 接口获取。

 

 1         public static void Send()
 2         {
 3             dynamic postData = new ExpandoObject();
 4             postData.touser = "OpenId";
 5             postData.template_id = "template_id";
 6             postData.url = string.Empty;
 7             postData.topcolor = "#FF0000";
 8             postData.data = new ExpandoObject();
 9             var data = new[]
10             {
11                 new Tuple<string, string, string>("title", "航班延误通知", "#FF0000"),
12                 new Tuple<string, string, string>("trainNumber", "10分钟", "#FF0000"),
13                 new Tuple<string, string, string>("fromto", "上海-北京", "#FF0000"),
14                 new Tuple<string, string, string>("formerTime", "2015/7/31 14:36:32", "#FF0000"),
15                 new Tuple<string, string, string>("Time", "2015/07/31 14:36:32", "#FF0000"),
16                 new Tuple<string, string, string>("number", "10分钟", "#FF0000"),
17                 new Tuple<string, string, string>("reason", "天气原因", "#FF0000"),
18                 new Tuple<string, string, string>("remark", "请关注我们的微信通知", "#FF0000")
19             };
20             var dataDict = (IDictionary<string, object>)postData.data;
21             foreach (var item in data)
22             {
23                 dataDict.Add(item.Item1, new { value = item.Item2, color = item.Item3 });
24             }
25             string json = ((object)postData).Serialize();
26 
27             Console.WriteLine(json);
28             var r = NetUtils.CreateHttpResponse(@"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=@access_token", json);
29             Console.WriteLine(r);
30         }

 

微信推送模板消息

标签:

原文地址:http://www.cnblogs.com/x1988z/p/4693509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!