zoukankan      html  css  js  c++  java
  • 微信推送模板消息

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

    @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         }
  • 相关阅读:
    机器学习:深入理解 LSTM 网络 (一)
    熵、交叉熵、相对熵(KL 散度)意义及其关系
    熵、交叉熵、相对熵(KL 散度)意义及其关系
    概率分布的 perplexity
    概率分布的 perplexity
    ImageNet 数据集
    i++与++i的区别,使用实例说明
    [置顶] ARM指令集和常用寄存器
    求大数阶数
    Wi-Fi漫游的工作原理
  • 原文地址:https://www.cnblogs.com/x1988z/p/4693509.html
Copyright © 2011-2022 走看看