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");
搞掂!这样对方微信就可以收到消息了