小程序发送模板消息(小程序内部发送)

本文详细介绍了如何在微信小程序中使用API发送模板消息,包括获取access_token、构造请求参数及调用接口的具体步骤,是开发者实现小程序消息推送功能的重要参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

index.wxml

<form bind:submit="testSubmit" report-submit="true">

<button formType="submit">发送模板消息</button>

</form>

===============================================================================================

index.js

testSubmit:function(e){

var self= this;

wx.request({

url:'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxf70bdc5019232340381234&secret=6ada2f125549123344e23ace32340bb739ef59f',

success: function (res) {

var _access_token=res.data.access_token;

var url='https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token='+_access_token;

var jsonData = {

access_token: _access_token,

touser: 'ogGVN5Se0p3BEtTgWsKMXffdglHs',

template_id: 'ws234dg1Rlacht619ng4234oYZSaMcP43gbvRDzWSNQPtet4R7pe_0',

form_id:'154451242396626',

page: "pages/index/index",

data: {

"keyword1": { "value": "测试数据一", "color": "#173177" },

"keyword2": { "value": "测试数据二", "color": "#173177" },

"keyword3": { "value": "测试数据三", "color": "#173177" },

"keyword4": { "value": "测试数据四", "color": "#173177" },

"keyword5": { "value": "测试数据四", "color": "#173177" },

"keyword6": { "value": "测试数据四", "color": "#173177" },

"keyword7": { "value": "测试数据四", "color": "#173177" },

}

}

wx.request({

url: url,

data: jsonData,

method: 'post',

success: function (res) {

console.log(1)

console.log(res)

},

fail: function (err) {

console.log(2)

console.log('request fail ', err);

},

complete: function (res) {

console.log(3)

console.log("request completed!");

}

})

}

})

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值