wxml文件:formbind:submit="testSubmit"report-submit="true"hidden="{{emptyprompt}}"buttonformType="submit"发送模板消息/button/formjs文件:testSubmit:function(e){varself=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_SECRETmethod:'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('requestfail',err);}})}

TAG标签: 微信小程序小程序微信小程序推送消息

http://www.xiaochengxub.com/read-107526.html