微信公众号发送模板消息

1.微信公众平台申请模板,得到模板ID

2.代码

  //发送微信消息
public static object SendWechatMsg2(string archiveNames, string firststr, string content, string url, string openid, string templateid = "") { url = "";
// obj的格式是模板申请的格式 var obj = new { first = new { value = firststr }, keyword1 = new { value = archiveNames }, keyword2 = new { value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }, remark = new { value = content } }; var sendResult = SendTemplateMsg1(openid, url, obj, templateid); return sendResult; } //url 是点击消息时跳转的页面,不填的话 "" 不跳转
//命名空间Senparc.Weixin.MP.AdvancedAPIs public static object SendTemplateMsg1(string openid, string url, object jsondata, string templateid) { if (string.IsNullOrEmpty(templateid)) { templateid = TemplateId; } SendTemplateMessageResult sendResult; try { sendResult = TemplateApi.SendTemplateMessage(AppId, openid, templateid, url, jsondata); } catch (Exception e) { string str = e.ToString(); throw; } object result = sendResult; return "AppId:" + AppId + "||||openid:" + openid + "||||templateid:" + templateid + "||||url:" + url + "||||result" + result; }

  

posted on 2021-07-07 16:45  heihaha  阅读(170)  评论(0编辑  收藏  举报