一、请求后端得到AccessToken
onLoad: function () {
wx.request({
url: ‘http://192.168.72.1162:8080/getAccessToken’,//
method: ‘GET’,
header: {
‘content-type’: ‘application/json’ // 默认值
},
success: function (res) {
app.globalData.ACCESS_TOKEN = res;
}
})
},
二,登录请求后端得到openid
wx.login({
success: function (res) {
if (res.code) {
console.log(“res.code=” + res.code)
wx.request({
url: ,//补充接口地址
data: {
code: res.code
},
success:function(result){
wx.setStorageSync(‘openid’, result.data.data.openid);
}
})
} else {
console.log(‘失败’ + res.errMsg)
}
}
})
三、发送信息
sendMessage:function(e){
console.log(“formId”);
console.log(e);
let _jsonData =
{
“touser”: wx.getStorageSync(‘openid’),
“weapp_template_msg”: {
“template_id”:app.globalData.template_id,
//服务通知中进入小程序的入口
“page”: “pages/index/index”,
“form_id”: e.detail.formId,
“data”: {
“keyword1”: {
“value”: “内容”
},
“keyword2”: {
“value”: “信息”
},
“keyword3”: {
“value”: “时间”
}
},
"emphasis_keyword": "keyword1.DATA"
}
}
wx.request({
url:’’,//发送消息接口
data: _jsonData,
method: ‘POST’,
header: {
‘content-type’: ‘application/json’ // 默认值
},
success:function(res){
console.log(“res”)
console.log(res)
}
})
console.log(“发送”)
}
})