微信服务号推送模板消息 微信服务号推送模板消息接口

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

微信服务号推送模板消息 微信服务号推送模板消息接口

-Xu-Zhao-   2021-03-21 我要评论
想了解微信服务号推送模板消息接口的相关内容吗,-Xu-Zhao-在本文为您仔细讲解微信服务号推送模板消息的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:微信推送模板,微信公众号推送模板,微信公众平台推送模板,下面大家一起来学习吧。

微信服务号现在用的比较火,用户可以通过微信号订阅信息,有时候会用到模板消息。下面贴上代码,有注释写的很详细。在此@access_token 请调用 https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=@appid&secret=@secret 接口获取。

具体代码:

public static void Send()
   {
    dynamic postData = new ExpandoObject();
    postData.touser = "OpenId";
    postData.template_id = "template_id";
    postData.url = string.Empty;
    postData.topcolor = "#FF";
    postData.data = new ExpandoObject();
    var data = new[]
    {
     new Tuple<string, string, string>("title", "航班延误通知", "#FF"),
     new Tuple<string, string, string>("trainNumber", "分钟", "#FF"),
     new Tuple<string, string, string>("fromto", "上海-北京", "#FF"),
     new Tuple<string, string, string>("formerTime", "// ::", "#FF"),
     new Tuple<string, string, string>("Time", "// ::", "#FF"),
     new Tuple<string, string, string>("number", "分钟", "#FF"),
     new Tuple<string, string, string>("reason", "天气原因", "#FF"),
     new Tuple<string, string, string>("remark", "请关注我们的微信通知", "#FF")
    };
    var dataDict = (IDictionary<string, object>)postData.data;
    foreach (var item in data)
    {
     dataDict.Add(item.Item, new { value = item.Item, color = item.Item });
    }
    string json = ((object)postData).Serialize();
    Console.WriteLine(json);
    var r = NetUtils.CreateHttpResponse(@"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=@access_token", json);
    Console.WriteLine(r);
   }

以上就是本文针对微信服务号推送模板消息接口的全部内容,希望对大家有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们