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

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!");

}

})

}

})

}

猜你喜欢

转载自blog.csdn.net/qq_42449958/article/details/84969189