参考官方文档和部分资料,总结小程序模板消息推送以及相关注意事项,楼主踩过的坑,特来与大家分享。
一、开发准备:
1.在微信公众平台-小程序的模板中心申请消息模板
二、实现原理:
文档示例:小程序 + 接口(PHP)
小程序部分:
话不多说,先上效果图:
示例代码:
<form bindsubmit="formSubmit" report-submit='true' > <view class="btn-area"><button formType="submit">Submit</button></view></form>formSubmit: function (e) { console.log('form发生了submit事件,formId为:', e.detail) var that = this; wx.request({ url: 'https://api.XXX.com/sendTemplateMessage.api', data: { uid: uid, formId: e.detail.formId }, method: 'post', header: {'content-type': 'application/x-www-form-urlencoded'}, //使用这种方式后台才能实现获取到数据 success: function (res) { console.log("发送模板:" + res.data) } })注意事项:
小程序通submit点击事件获formid在安卓和IOS是不一样的,安卓系统中为13位时间戳,而IOS系统中为32位字符串,在做接口请求时,不需要做额外处理。
安卓系统 IOS系统















