定义的模版内容:
- {{first.DATA}}
-
- 商品名称:{{product.DATA}}
- 商品价格:{{price.DATA}}
- 购买时间:{{time.DATA}}
- {{remark.DATA}}
代码:
- protected void Page_Load(object sender, EventArgs e)
- {
-
- if (!AccessTokenContainer.CheckRegistered(appId))
- {
- AccessTokenContainer.Register(appId, appSecret);
- }
-
- string access_token = AccessTokenContainer.GetAccessTokenResult(appId).access_token;
- string openId = "xxxxxx";
- string templateId = "xxxxxx";
- string linkUrl = "http://www.baidu.com"; //点击详情后跳转后的链接地址,为空则不跳转
-
-
- var templateData = new ProductTemplateData()
- {
- first = new TemplateDataItem("您好,您的订单已支付成功!", "#000000"),
- product = new TemplateDataItem("旺旺大礼包", "#000000"),
- price = new TemplateDataItem("99.8元", "#000000"),
- time = new TemplateDataItem("2016-11-09 16:50:38", "#000000"),
- remark = new TemplateDataItem("感谢您的光临~", "#000000")
- };
-
- SendTemplateMessageResult sendResult = TemplateApi.SendTemplateMessage(access_token, openId, templateId, "", linkUrl, templateData);
-
-
- if (sendResult.errcode.ToString() == "请求成功")
- {
-
- }
- else
- {
- Response.Write("出现错误:" + sendResult.errmsg);
- }
- }
-
- 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; }
- }
推送效果图:
|
请发表评论