微信公衆平臺 模版消息


1.在模板庫取模版編號,如TM00335

var msgData = new { template_id_short = "TM00335" };

  var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string json = serializer.Serialize((object)msgData);  var postUrl = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token="+access_token;
            string result = Helper.NetHelper.CallWebPage3(postUrl, json, ASCIIEncoding.UTF8, "text/json");
            Response.Write(result);



從result取到template_id


2.然後

 Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("first", new { value = "恭喜你積分成功!", color = "#173177" });
            data.Add("account", new { value = "***", color = "#173177" });

           。。。


   var msgData =
              new
              {
                  touser = "openid",
                  template_id = "   template_id",
                  topcolor = "#FF0000",
                  url = "",
                  data = data
              };


            //var msgData = new { template_id_short = "TM00335" };
            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string json = serializer.Serialize((object)msgData);
            var postUrl = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=zA6sqpChVwf3UW8ZjuRdFFVZ8lBaonhwGMVN1XjGBCSDac-hIMTvRxjCbpsEYWBLde_xDeaWwwSJystWP08T846G9CdBche7L7lbFeA4Fsc");
         //  var postUrl = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=zA6sqpChVwf3UW8ZjuRdFFVZ8lBaonhwGMVN1XjGBCSDac-hIMTvRxjCbpsEYWBLde_xDeaWwwSJystWP08T846G9CdBche7L7lbFeA4Fsc";
            Helper.NetHelper.CallWebPage3(postUrl, json, ASCIIEncoding.UTF8, "text/json");


搞掂!這樣對方微信就可以收到消息了

發佈了46 篇原創文章 · 獲贊 9 · 訪問量 14萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章