• 微信推送模板消息


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

    @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         }
  • 相关阅读:
    实践 Agile Web Development 4th edition 时碰到的问题汇总
    [AWDwR4] Iteration F4
    [AWDwR4] Getting AJAX to work in Rails 3 with jQuery
    [翻译]理解C#对象生命周期
    c# asp.net 正则表达式(12)
    Application对象 简单的聊天室(16)
    c# response输出文件实例(14)
    c# asp.net fileupload实例(10)
    c# asp.net 获取客户端表单的数据(15)
    c# Request对象(13)
  • 原文地址:https://www.cnblogs.com/x1988z/p/4693509.html
Copyright © 2020-2023  润新知