<?php
function sendTemplateMsg(){
$access_token = 'uI0hLI1csZOs-WBP12F5E1mjojLlU1IJK3CIemtVF9XXDPOEKgDmiKqDkRCpEjTVDjgHzrWPH5eKt1hqdyE3eqB2iLZnoweZ9nZH2NC_3BbKneCzlsUieugwOMaUml3bCDQbAFANOB';
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
$array = array(
'touser'=>'ovBdUwIs50k9o_ZMx8YFrKIfBCzY',
'template_id'=>'supgjJ19TVDt4IqD3j19ftbnBhGwObegTIByo_hFgdQ', //点击模板消息后的跳转链接
'url'=>'http://www.baidu.com/',
'data'=>array(
'name'=>array('value'=>'三只松鼠','color'=>'#173177'),
'money'=>array('value'=>338,'color'=>'#173177'),
'date'=>array('value'=>date("Y-m-d h:i:s"),'color'=>'#173177'),
),
);
//转换成json格式
$postJson = json_encode($array);
//$res = $this->http_curl($url,'post','json',$postJson);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postJson);
$res = curl_exec($ch);
if(curl_errno($ch)){
var_dump(curl_error($ch));
}
curl_close($ch);
var_dump($res);
}
sendTemplateMsg();
?>
这是我写的php文件,上传到服务器后,一打开这个页面,会不断的发送模板消息到我的个人微信(理论上是一条的),不知道哪里出问题了(access_token在当时肯定有效,要不然也发不出模板消息)