模板消息仅用于公众号向用户发送重要的服务通知,只能用于符合其要求的服务场景中,如信用卡刷卡通知,商品购买成功通知等。不支持广告等营销类消息以及其它所有可能对用户造成骚扰的消息。
要开发模版消息,总共分以下几部
1 设置所属行业
也就是发送的模版消息属于什么行业,比如购买通知,提醒通知,缴费通知等,主要是为了及时通知用户。
第一步就是选择自己推送的消息属于什么行业的消息
接口调用请求说明
http请求方式: POSThttps://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=ACCESS_TOKEN
- 1
- 2
POST数据说明
{ "industry_id1":"1", "industry_id2":"4" }
- 1
- 2
- 3
- 4
参数 | 是否必须 | 说明 |
---|---|---|
industry_id1 | 是 | 公众号模板消息所属行业编号 |
industry_id2 | 是 | 公众号模板消息所属行业编号 |
效果
2 添加模版消息
模版标题和模版内容
模版内容如下
{{first.DATA}}订单商品:{{keyword1.DATA}}订单编号:{{keyword2.DATA}}支付金额:{{keyword3.DATA}}支付时间:{{keyword4.DATA}}{{remark.DATA}}
- 1
- 2
- 3
- 4
- 5
- 6
添加模版消息之后就可以看到模板ID,这个模版ID在发送消息的时候会用到。
发送模版消息
接口地址
http请求方式: POSThttps://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
- 1
- 2
提交json如下
{ "touser":"要发送用户的openid", "template_id":"DIW1KiYcwpH2wzJkeYe-jZr7kjsKND8sDSc362iQ0wU", "url":"点击模版消息跳转的地址", "data":{ "first": { "value":"您好,您的签到已被确认。\n", "color":"#173177" }, "keyword1":{ "value":"程高伟", "color":"#173177" }, "keyword2": { "value":"15300000000", "color":"#173177" }, "keyword3": { "value":"陕西师范大学", "color":"#173177" }, "keyword4": { "value":"2017年3月8日", "color":"#173177" }, "remark":{ "value":"快去学习吧,少年!", "color":"#173177" } } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31