protected void Page_Load(object sender, EventArgs e) { //根据appId判断获取 if (!AccessTokenContainer.CheckRegistered(appId)) //检查是否已经注册 { AccessTokenContainer.Register(appId, appSecret); //如果没有注册则进行注册 } string access_token = AccessTokenContainer.GetAccessTokenResult(appId).access_token; //AccessToken string openId = "xxx"; //用户openId string templateId = "xxx"; //模版id string linkUrl = "xxx"; //路径地址 //为模版中的各属性赋值 var templateData = new ProductTemplateData() { first = new TemplateDataItem("您好,您的订单已支付成功!", "#000000"), product = new TemplateDataItem("水果沙拉", "#000000"), price = new TemplateDataItem("8元", "#000000"), time = new TemplateDataItem("2021-05-20 10:46:33", "#000000"), remark = new TemplateDataItem("有空再来u~u", "#000000") }; SendTemplateMessageResult sendResult = TemplateApi.SendTemplateMessage(access_token, openId, templateId, "", linkUrl, templateData); //发送成功 if (sendResult.errcode.ToString() == "请求成功") { //... } else { Response.Write("出现错误:" + sendResult.errmsg); } } /// <summary> /// 定义模版中的字段属性(需与微信模版中的一致) /// </summary> public class ProductTemplateData { public TemplateDataItem first { get; set; } public TemplateDataItem product { get; set; } public TemplateDataItem price { get; set; } public TemplateDataItem time { get; set; } public TemplateDataItem remark { get; set; } }