2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 微信小程序实现消息推送(调用小程序推送模板接口) 完整示例

微信小程序实现消息推送(调用小程序推送模板接口) 完整示例

时间:2022-10-03 00:37:25

相关推荐

微信小程序实现消息推送(调用小程序推送模板接口) 完整示例

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./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./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": "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);}})}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。