<?php
//设置与发送模板信息
function set_msg($datas){
//appid与appsecret改成你自己的
$appid = $datas['appid'];
$appsecret = $datas['appsecret'];
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data,true);
//获取access_token
$access_token = $data['access_token'];
$formwork =array(
'touser'=>'oWpfddffdsfsdafasdfasd',//服务号公众平台下获取的用户openid
'template_id'=>'-z4Eg5lBbDZ1WHMz0tkBE7pJJ-Smf9AKFGGanj-0xdU',
'url'=>'http://www.bzon.com.cn',
'topcolor'=>'#FF0000',
'data'=>array(
'first'=>array('value'=>'恭喜您,试用申请通过!','color'=>'#173177'),
'keyword1'=>array('value'=>'BK000000001','color'=>'#173177'),
'keyword2'=>array('value'=>'您好,您申请我司的《博纵旅游批发版》试用账号密码已被通过!。','color'=>'#173177'),
'remark'=>array('value'=>'赶紧登陆用户中心体验吧!','color'=>'#173177')
)
);
$formwork = json_encode($formwork);
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$datas['appid'] = 'wx666caadasdfasd5ad8b92';//服务号appid
$datas['appsecret'] = 'a984d29fasdfadsfasdfasdfXX72fde';//服务号secret
echo set_msg($datas);
?>
微信模板消息案例
最新推荐文章于 2024-08-18 02:19:03 发布