小程式傳送模板訊息(小程式內部發送)
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!");
}
})
}
})
}