微信服务号推送模板消息接口
程序员文章站
2023-12-10 23:45:10
微信服务号现在用的比较火,用户可以通过微信号订阅信息,有时候会用到模板消息。下面贴上代码,有注释写的很详细。在此@access_token 请调用 接口获取。
具体代码...
微信服务号现在用的比较火,用户可以通过微信号订阅信息,有时候会用到模板消息。下面贴上代码,有注释写的很详细。在此@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); }
以上就是本文针对微信服务号推送模板消息接口的全部内容,希望对大家有所帮助。