微信小程序实现消息推送(调用小程序推送模板接口)完整示例
微信小程序实现消息推送(调用小程序推送模板接口)完整示例
wxml文件: <form bind:submit=”testSubmit” report-submit=”true” hidden=”{{emptyprompt}}”> <button formType=”submit”>发送模板消息</button> </form>js文件:testSubmit: function (e) { var self = this;//获取access_token :APPID为小程序appid,app_secret为小程序密钥 wx.request({ url: ‘https://api.weixin.qq.com/cgi-bin/token? grant_type=client_credential&appid=APPID&secret=APP_SECRET method: ‘GET’, success: function (res) { self.setData({ access_token: res.data.access_token })//发送模板消息 需要注意的是openid需为触发当前事件人的openid,不然收不到推送消息wx.request({url: ‘https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send? access_token=access_token’,data: { “touser”: self.data.openid, //接收者(用户)的 “template_id”: template_id, //所调用的小程序模板id “page”: “pages/index/index”, “form_id”: self.data.payid,//支付场景下为本次支付的 prepay_id //”form_id”: e.detail.formId,// 表单提交场景下为 submit 事件带上的 formId “data”: { “keyword1”: { “value”: “339208499” }, “keyword2”: { “value”: “2015年01月05日 12:30” }, “keyword3”: { “value”: “腾讯微信总部” }, “keyword4”: { “value”: “广州市海珠区新港中路397号” } }, “emphasis_keyword”: “keyword1.DATA” //要放大的数据 }, method: ‘POST’, header: { ‘content-type’: ‘application/json’ }, success: function (res) { console.log(res) }, fail: function (err) { console.log(‘request fail ‘, err); }})}
- 刺猬QQ交流群号多少?
- 363432
- 刺猬官方有技术支持吗?
- 有的,但技术支持是有偿服务哦,咨询右下角的在线客服吧!
- 下载的资源不能使用怎么办?
- 如果在本站下载的资源不能使用,一经确认可以联系在线客服退款。