时间:2019-05-05 来源:小程序工厂
/***:
似乎好多人都是用后台调用的
发送模板消息”的api接口(https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN)
/***:
为了大家能看全 !我再贴些代码如下:
//form表单提交触发的事件
changeIntoIdentification:function(e){
var that=this;
var currentStatu = e.currentTarget.dataset.statu;
that.util(currentStatu)
var formId = e.detail.formId;
console.log("formI 》"+formId+"《《《");
that.setData({
showModalStatus: false,
changeIntoIdentification: e.detail.value.changeIntoIdentification
});
var changeIntoIdentification = that.data.changeIntoIdentification;
var identification = wx.getStorageSync("identification");
var rgisterName = wx.getStorageSync("rgisterName");
if (identification != changeIntoIdentification && changeIntoIdentification != ""){
wx.request({
url: 'https://www.gcjxglzx.com/' + "*******" +'/getUserInfoByCondition',
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
if (res.data.status == '0' && res.data.data != null){
var changeIntoRegisterName = res.data.data[0].registerName;
var wxUser = res.data.data[0].wxUser //转入人的消息推送的微信
var len = changeIntoRegisterName.length - 1;
var xing = '';
for (var i = 0; i < len; i++) {
xing+= '*';
}
that.setData({
hiddenmodalput: true
});
var name = changeIntoRegisterName.substring(0, 1) + xing;
wx.showModal({
title: '是否将设备转给',
content: name,
success: function (res) {
if (res.confirm) {
var url = that.data.messagePushUrl
if (url != null && url != ""){
var time = new Date();
//*******************************重点在下边*************************//
wx.request({
url: url,//发送模版消息的接口地址,已经拼接里access_token
//
method: 'POST',
header: {
'content-type': 'application/json'
},
data:{
touser: wxUser,//接收消息的用户
template_id: "_-dTL2OwXZJDsRDymy4I4K3HS2-v-GH27pQyV-_jWw4",
page:"/page-payImg/payImg",
form_id: formId,
value: {
keyword1: { //申请人
value: rgisterName,
color: "#173177"
},
keyword2: {//详情
value: that.data.device.machineryType + that.data.device.deviecBrand + that.data.device.plateSubject+"设备申请转入!点击下方查看详情",
color: "#173177"
},
keyword3: {//时间
value: "2015年01月05日 12:30",
color: "#173177"
},
},
emphasis_keyword: "keyword2.DATA"
},
success: function (resmsg) {
var errcode = resmsg.data.errcode
console.log("发送状态>>>>"+errcode);
}
})
}
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}else{
wx.showToast({
title: '提醒转入人注册或重新添加转入人',
duration: 2500,
mask: true
});
that.setData({
hiddenmodalput: false
});
//************上面的请求是调用微信小程序发送模板消息的接口!为啥一直是form_id**********************//
}
}
})
} else if (identification == changeIntoIdentification || changeIntoIdentification == ""){
wx.showToast({
title: '转入人错误',
duration: 2500,
mask:true
})
}
},
51微信小程序margin重叠,微信小程序开发
/***:
问题解决了!formid 获取到之后只要调用了wx.request() 方法,就算这个formid没用过也会失效!所以整个方法区只能在第一个wx.request()的方法内使用formid