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         }
  • 相关阅读:
    Elasticsearch集成IKAnalyzer分析器
    Elasticsearch操作Document文档
    ElasticSearch简介
    Lucene查询索引
    Lucene索引维护(添加、修改、删除)
    Lucene使用IKAnalyzer分词
    Lucene搜索引擎入门
    MySQL优化(四)——读写分离
    MySQL优化(三)——主从复制
    Java 身份证验证工具类代码模板
  • 原文地址:https://www.cnblogs.com/x1988z/p/4693509.html
Copyright © 2011-2022 走看看