废话不多说直接上代码
小程序端:
wuliu:function(e){
var form_id = e.detail.formId //获取表单提交时产生的formId,用于发送模版消息
var orderid = e.detail.target.id
var id = e.detail.target.dataset.id
wx.request({
url: app.BASE_URL + '/coupons/messagewuliu.php',
data: {
touser: app.openid,
template_id: 'C8GzhTjFaJZBANG5oLD2p20ziXXXXXXXXXXXXXXX',
page: 'pages/index/index',
form_id: form_id,
orderid: orderid,
id:id
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
}
})
}
后台代码试例:
$url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=$access_token";
//模版接口
$data['touser'] = $_GET['touser']; //发送的openid
$data['template_id'] = $_GET['template_id']; //模版id
$data['page'] = $_GET['page']; //跳转页面
$data['form_id'] = $_GET['form_id']; //提交表单产生的form_id
$data['data']=array('keyword1'=>array('value'=>"value1"),'keyword2'=>array('value'=>$arrayss['ordernumber']),'keyword3'=>array('value'=>$arrays['goodname']),'keyword4'=>array('value'=>$arraywl['deliverynum']),'keyword5'=>array('value'=>$arraywl['mobile']),'keyword6'=>array('value'=>$arraywl['username']),'keyword7'=>array('value'=>$arraywl['province'].$arraywl['city'].$arraywl['country'].$arraywl['address']),'keyword8'=>array('value'=>$arraywl['company']));
if(isset($_GET['color'])){
$data['color'] = $_GET['color'];
}
if(isset($_GET['emphasis_keyword'])){
$data['emphasis_keyword'] = $_GET['emphasis_keyword'];
}
$result = $http->post($url,json_encode($data));
echo json_encode($result);
部分代码未完全写出,如有需要请联系qq或微信 :1103778812交流