微信服务号现在用的比较火,用户可以通过微信号订阅信息,有时候会用到模板消息。下面贴上代码,有注释写的很详细。在此@access_token 请调用 接口获取。
具体代码:
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); }
以上就是本文针对微信服务号推送模板消息接口的全部内容,希望对大家有所帮助。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论